角消退:变量未定义 [英] Angular Resolve: Variable is not defined

查看:99
本文介绍了角消退:变量未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与角路由工作,第一次和我最近提出的关于刷新丢失一些数据的问题,我得到的回答是使用的决心。这似乎是我一直在寻找解决方案,但是我不能让它正常工作。

\r
\r

的.config(['$ routeProvider',函数($ routeProvider){\r
           //决定通过重定向走快捷方式,点击主页上的图标管理发送routeProvider / MG然后用它来拉相关的HTML文件\r
           $ routeProvider\r
               。当('/ MG',{\r
                   控制器:'teammateController',\r
                   templateUrl:./assets/departments/department.html',\r
                   解析:{\r
                       activeDepartment:功能(){\r
                           回报管理\r
                       }\r
                   }\r
               })\r
               。当('/ PO',{\r
                   控制器:'teammateController',\r
                   templateUrl:./assets/departments/department.html',\r
                   解析:{\r
                       activeDepartment:功能(){\r
                           返回项目办公室\r
                       }\r
                   }\r
               })\r
               。当('/ SM',{\r
                   控制器:'teammateController',\r
                   templateUrl:./assets/departments/department.html',\r
                   解析:{\r
                       activeDepartment:功能(){\r
                           回报销售和营销\r
                       }\r
                   }\r
               })\r
               。什么时候('/', {\r
                   控制器:'teammateController',\r
                   templateUrl:home.html做为',\r
                   解析:{\r
                       activeDepartment:功能(){\r
                           的console.log(工作);\r
                           回家';\r
                       }\r
                   }\r
               })\r
               。除此以外({\r
                   控制器:'teammateController',\r
                   templateUrl:home.html做为',\r
                   解析:{\r
                       activeDepartment:功能(){\r
                           的console.log(工作);\r
                           回家';\r
                       }\r
                   }\r
               })\r
       }]);\r
\r
   app.controller('teammateController',功能teammateController($范围,$ HTTP,$ rootScope,$超时,空闲,$位置){\r
       $ scope.deptName = activeDepartment();\r
     });

\r

\r
\r

我收到的ReferenceError:activeDepartment没有定义。控制台日志的作品,我看工作,所以我知道的决心正在运行,但随后出现的错误消息。我用尽了一切我能想到的,我不能为我的生命看到我错了。任何帮助将是AP preciated。


解决方案

的决定属性注入到你的控制器,因此试试这个:

  app.controller('teammateController',功能teammateController($范围,$ HTTP,$ rootScope,$超时,空闲,$位置,activeDepartment){
   $ scope.deptName = activeDepartment;
 });

注意在控制器结束后额外的参数。

I am working with Angular Routes for the first time and I recently posed a question regarding a refresh losing some data, the answer I received was to use resolve. It seems to be the solution I was looking for however I cannot get it to work properly.

.config(['$routeProvider', function($routeProvider) {
           //determines redirects go via shortcuts, clicking on the management icon on the main page sends the routeProvider /MG which it then uses to pull the relevant HTML file
           $routeProvider
               .when('/MG', {
                   controller: 'teammateController',
                   templateUrl: './assets/departments/department.html',
                   resolve: {
                       activeDepartment: function() {
                           return 'Management'
                       }
                   }
               })
               .when('/PO', {
                   controller: 'teammateController',
                   templateUrl: './assets/departments/department.html',
                   resolve: {
                       activeDepartment: function() {
                           return 'Programs Office'
                       }
                   }
               })
               .when('/SM', {
                   controller: 'teammateController',
                   templateUrl: './assets/departments/department.html',
                   resolve: {
                       activeDepartment: function() {
                           return 'Sales And Marketing'
                       }
                   }
               })
               .when('/', {
                   controller: 'teammateController',
                   templateUrl: 'home.html',
                   resolve: {
                       activeDepartment: function() {
                           console.log("working");
                           return 'home';
                       }
                   }
               })
               .otherwise({
                   controller: 'teammateController',
                   templateUrl: 'home.html',
                   resolve: {
                       activeDepartment: function() {
                           console.log("working");
                           return 'home';
                       }
                   }
               })
       }]);

   app.controller('teammateController', function teammateController($scope, $http, $rootScope, $timeout, Idle, $location) {
       $scope.deptName = activeDepartment();
     });

I receive "ReferenceError: activeDepartment is not defined". The console log works and I see "working", so I know resolve is being run but, then the error message appears. I've tried everything I can think of and I cannot for the life of me see where I am going wrong. Any help would be appreciated.

解决方案

The resolved properties are injected into your controller, so try this:

app.controller('teammateController', function teammateController($scope, $http, $rootScope, $timeout, Idle, $location, activeDepartment) {
   $scope.deptName = activeDepartment;
 });

Notice the additional argument at the end of your controller.

这篇关于角消退:变量未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆