AngularJS $routeParams是未定义的
AngularJS $routeParams is undefined
我是AngularJS的新手,我试图在我的代码中使用$routeParams,在这里搜索以前的答案,我已经确保我已经添加了'$routeParams'作为我的数组注入和函数的一部分,我不使用ui-router模块。然而,当我试图记录它时,我仍然得到一个未定义的。
我的Angular应用如下:
var RAFITOAPP = RAFITOAPP || {}
RAFITOAPP.app = angular.module('app', [
'ngRoute'
]).config(['$routeProvider', function($routeProvider) {
$routeProvider.
when("/line/:userAccountId", {templateUrl: "assets/partials/line.html", controller: "LineController"}).
when("/floormap", {templateUrl: "assets/partials/floormap.html", controller: "MapController"}).
when("/report", {templateUrl: "assets/partials/reports.html", controller: "ReportController"}).
when("/addNew", {templateUrl: "assets/partials/add_new.html", controller: "addNewController"}).
when("/profile", {templateUrl: "assets/partials/account.html", controller: "accountSettingsController"}).
otherwise({redirectTo: '/line'});
}]);
我的控制器如下:
RAFITOAPP.app.
controller('LineController', ['$scope','$rootScope','$routeParams', function($rootScope, $scope, $location, $routeParams) {
$scope.$on('$viewContentLoaded', function() {
console.log($routeParams);
change('line');
if(control != 1){
setTimeout(function() {
script1fire();
} , 100);
control = 1;
}
})
}]);
请告诉我我错过了什么?任何帮助都将不胜感激。如果你想查看导致问题的HTML页面它是
您的数组依赖项和函数参数不相同。应该是这样的'['$rootScope', '$scope', '$location', '$routeParams', function($rootScope, $scope, $location, $routeParams)'
而不是'['$scope','$rootScope','$routeParams', function($rootScope, $scope, $location, $routeParams)'
RAFITOAPP.app
.controller('LineController', ['$rootScope', '$scope', '$location', '$routeParams',
function($rootScope, $scope, $location, $routeParams) {
$scope.$on('$viewContentLoaded', function() {
console.log($routeParams);
change('line');
if (control != 1) {
setTimeout(function() {
script1fire();
}, 100);
control = 1;
}
})
}
]);
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- $routeParams在传递到新视图时未定义&控制器
- $routeParams在angularjs中未定义
- AngularJS $routeParams是未定义的