<tfoot id='CK9lS'></tfoot>

  • <legend id='CK9lS'><style id='CK9lS'><dir id='CK9lS'><q id='CK9lS'></q></dir></style></legend>
    <i id='CK9lS'><tr id='CK9lS'><dt id='CK9lS'><q id='CK9lS'><span id='CK9lS'><b id='CK9lS'><form id='CK9lS'><ins id='CK9lS'></ins><ul id='CK9lS'></ul><sub id='CK9lS'></sub></form><legend id='CK9lS'></legend><bdo id='CK9lS'><pre id='CK9lS'><center id='CK9lS'></center></pre></bdo></b><th id='CK9lS'></th></span></q></dt></tr></i><div id='CK9lS'><tfoot id='CK9lS'></tfoot><dl id='CK9lS'><fieldset id='CK9lS'></fieldset></dl></div>

      <small id='CK9lS'></small><noframes id='CK9lS'>

        • <bdo id='CK9lS'></bdo><ul id='CK9lS'></ul>
      1. 在ui-router中的当前状态下如何绑定相关值?

        how to bind the relevant value in case of current status in ui-router?(在ui-router中的当前状态下如何绑定相关值?)
          <bdo id='u9EDx'></bdo><ul id='u9EDx'></ul>
            <tbody id='u9EDx'></tbody>

            <small id='u9EDx'></small><noframes id='u9EDx'>

              <i id='u9EDx'><tr id='u9EDx'><dt id='u9EDx'><q id='u9EDx'><span id='u9EDx'><b id='u9EDx'><form id='u9EDx'><ins id='u9EDx'></ins><ul id='u9EDx'></ul><sub id='u9EDx'></sub></form><legend id='u9EDx'></legend><bdo id='u9EDx'><pre id='u9EDx'><center id='u9EDx'></center></pre></bdo></b><th id='u9EDx'></th></span></q></dt></tr></i><div id='u9EDx'><tfoot id='u9EDx'></tfoot><dl id='u9EDx'><fieldset id='u9EDx'></fieldset></dl></div>
                <tfoot id='u9EDx'></tfoot>

                • <legend id='u9EDx'><style id='u9EDx'><dir id='u9EDx'><q id='u9EDx'></q></dir></style></legend>
                  本文介绍了在ui-router中的当前状态下如何绑定相关值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在每个 .state 中附加了数据属性来识别用户(经过身份验证的或公开的)如下(一个状态示例)

                  I have attached data attribute in each .state to identify the user (authenticated or public) as following (one state example)

                  $stateProvider
                   .state('admin-panel.public.home', {
                      url: '/p',
                      templateUrl: 'app/public/home.tmpl.html',
                      controller: 'PublicHomeController',
                      controllerAs: 'ctrl',
                      data: {
                          requireLogin: false
                      }
                  });
                  

                  我需要以用户(已验证和公开)的某些状态为例

                  I need to use the some state for both of user (authenticated and public) as an example

                  .state('403', {
                      url: '/403',
                      templateUrl: '403.tmpl.html',
                      controller: function($scope, $state, APP, Auth) {
                          $scope.app = APP;
                  
                          $scope.goHome = function() {
                              if(Auth.isAuthenticated()){
                                  $scope.requireLogin = true;
                                  $state.go('admin-panel.default.home');
                              }
                              else{
                                  $scope.requireLogin = false;
                                  $state.go('admin-panel.public.home');
                              }
                          };
                      },
                      data: {
                          requireLogin: $scope.requireLogin
                      }                
                  
                  })
                  

                  在这里,当经过身份验证的用户访问此状态时,我需要将 true 值传递给 requireLogin: true 以及当公共用户访问此状态时,我需要传递 false值为 requireLogin: false.如上所述,我在 controller 中检查了当前用户状态.如何将 $scope.requireLogin 绑定到数据属性?

                  Here when the authenticated user access this state I need to pass the true value to requireLogin: true as well when public user access this state I need to pass the false value as requireLogin: false. I checked the current user status in the controller as above. How can I bind the $scope.requireLogin to data attribute?

                  ui-router高手请指教解决办法???

                  Anyone in expert of ui-router please tell a way to solve???

                  推荐答案

                  你可以用一种非常干净的方式解决你的问题.让我们从添加到 bodyhtml 标签的全局控制器示例 GlobalCtrl 开始,例如 ng-controller="GlobalCtrl.

                  You can solve your problem in a very cleaner way. Let's start with a global controller example GlobalCtrl which is added to the body or html tag like ng-controller="GlobalCtrl.

                  这样做将使我们能够在整个单页 Angular 应用程序中保持此 GlobalCtrl 的范围(当您使用 ui-router 时),我们可以避免使用$rootScope 的用法(实际上是在模仿 $rootScope 的用法).

                  Doing this will enable us to keep the scope of this GlobalCtrl throughout your single page Angular app (as you are using ui-router) and we can avoid the usage of $rootScope (actually mimicking the usage of $rootScope).

                  现在,在您的 GlobalCtrl 中定义如下内容:

                  Now, inside your GlobalCtrl define something like this:

                  // Using an object to avoid the scope inheritance problem of Angular
                  // https://github.com/angular/angular.js/wiki/Understanding-Scopes
                  $scope.globalData = {};
                  
                  // Will be called everytime before you start navigating to any state
                  $scope.$on('$stateChangeStart', function(event, toState, toParams) {
                      $scope.globalData.requireLogin = false;
                      var statesToLoginCheck = ['403', 'foo', 'bar']; // and other states on which you want to check if user is logged in or not
                  
                      // If the current state on which we are navingating is allowed to check for login
                      if (statesToLoginCheck.indexOf(toState.name) > -1) {
                          if (Auth.isAuthenticated()) {
                              $scope.globalData.requireLogin = true;
                              $state.go('admin-panel.default.home');
                          } else {
                              $scope.globalData.requireLogin = false;
                              $state.go('admin-panel.public.home');
                          }
                  
                          event.preventDefault();
                          return;
                      }
                  });
                  

                  现在,由于 GlobalCtrl$scopebodyhtml 中,那么每个状态或指令都会继承此 GlobalCtrl 的范围,然后您只需签入变量 $scope.globalData.requireLogin 的任何控制器.

                  Now, since $scope of GlobalCtrl is in body or html then every state or directive will inherit the scope of this GlobalCtrl and then you simply have to check in your any controller of variable $scope.globalData.requireLogin.

                  这篇关于在ui-router中的当前状态下如何绑定相关值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                      1. <i id='vbOsK'><tr id='vbOsK'><dt id='vbOsK'><q id='vbOsK'><span id='vbOsK'><b id='vbOsK'><form id='vbOsK'><ins id='vbOsK'></ins><ul id='vbOsK'></ul><sub id='vbOsK'></sub></form><legend id='vbOsK'></legend><bdo id='vbOsK'><pre id='vbOsK'><center id='vbOsK'></center></pre></bdo></b><th id='vbOsK'></th></span></q></dt></tr></i><div id='vbOsK'><tfoot id='vbOsK'></tfoot><dl id='vbOsK'><fieldset id='vbOsK'></fieldset></dl></div>
                        <tfoot id='vbOsK'></tfoot>
                          <bdo id='vbOsK'></bdo><ul id='vbOsK'></ul>

                          <small id='vbOsK'></small><noframes id='vbOsK'>

                              <tbody id='vbOsK'></tbody>
                            <legend id='vbOsK'><style id='vbOsK'><dir id='vbOsK'><q id='vbOsK'></q></dir></style></legend>