admin管理员组文章数量:1424893
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. However I am still getting an undefined when I try to log it.
My Angular App is as follows:
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
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. However I am still getting an undefined when I try to log it.
My Angular App is as follows:
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
Share Improve this question edited May 18, 2015 at 6:05 alyn000r asked May 18, 2015 at 5:37 alyn000ralyn000r 5662 gold badges8 silver badges20 bronze badges 6- Try this controller('LineController', ['$scope','$rootScope','$location', '$routeParams', function( $scope,$rootScope, $location, $routeParams) { your code } ); Also instead of $scope.on try $rootScope.on – Abdul Hamid Commented May 18, 2015 at 5:51
- are you sure the $viewContentLoaded event is fired? because you attach it to $scope instead of $rootScope – Moshe Shaham Commented May 18, 2015 at 5:51
- @Inventillect I have tried what you suggested and still the same thing – alyn000r Commented May 18, 2015 at 5:53
- @Moshe Shaham I believe it is firing because the scriptfire1 is happening. – alyn000r Commented May 18, 2015 at 5:53
- your parameters are not same. – Abdul Hamid Commented May 18, 2015 at 5:55
1 Answer
Reset to default 6Your 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)'
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;
}
})
}
]);
本文标签: javascriptAngularJS routeParams is undefinedStack Overflow
版权声明:本文标题:javascript - AngularJS $routeParams is undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745421502a2657919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论