我是AngularJS的新手,我尝试在代码中使用$ routeParams,在此处搜索以前的答案,确保已在数组注入和函数中添加了“ $ routeParams”,并且未使用ui路由器模块。但是,当我尝试记录它时,我仍然得到一个未定义的信息。

我的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 - AngularJS $ routeParams未定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30295781/

10-11 23:39