简体   繁体   English

AngularJS $ routeParams未定义

[英]AngularJS $routeParams is undefined

I am a newbie to AngularJS and I am trying to use $routeParams in my code, searching the previous answers here I have made sure that I have added '$routeParams' as part of my array injection and the function both and I am not using ui-router module. 我是AngularJS的新手,我尝试在代码中使用$ routeParams,在此处搜索以前的答案,确保已在数组注入和函数中添加了“ $ routeParams”,并且未使用ui路由器模块。 However I am still getting an undefined when I try to log it. 但是,当我尝试记录它时,我仍然得到一个未定义的信息。

My Angular App is as follows: 我的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'});
}]);

My Controller is as follows: 我的控制器如下:

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;
        }
    })
}]);

Please advise on what am I missing ? 请告知我我想念什么? Any help will be appreciated greatly. 任何帮助将不胜感激。 If you wish to see the HTML Page causing the issue it is 如果您希望看到导致问题的HTML页面,那就是

Your array dependencies and functions arguments are not same. 您的数组依赖项和函数参数不相同。 it should be something like this '['$rootScope', '$scope', '$location', '$routeParams', function($rootScope, $scope, $location, $routeParams)' instead of '['$scope','$rootScope','$routeParams', function($rootScope, $scope, $location, $routeParams)' 应该是这样的东西'['$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; } }) } ]); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM