gpt4 book ai didi

javascript - 无法访问我的 angularjs Controller 中的 $routeParams

转载 作者:行者123 更新时间:2023-12-03 09:34:52 26 4
gpt4 key购买 nike

            var myApp = angular.module('myApp', ['ngGrid', 'ngRoute']);

myApp.config(['$routeProvider', function ($routeProvider)
{
$routeProvider.
when('/:energyId/:energyChain/:resourceId/:facilityId',
{
templateUrl: '/Content/resourceTemplate.html',
controller: 'detailsController'

}).
otherwise({
redirectTo: '/param1/param1/param1/param1'
});
}]);

myApp.controller('detailsController', ['$scope', function ($scope,$routeParams) {

//here the error when i add the following single statement
$scope.status = $routeParams.energyID;//This cuases angular to fail but only this controller

$scope.models = [
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" },
{ Parameter: "Bob", Period: 25, Values: "NewYork", Scale: "NewYork", Unit: "NewYork", Per: "NewYork" }

];


}]);

我已经测试了我的代码,它一直有效,直到我在访问 $routeParams 的 Controller 中添加了 status 变量。错误显示无法访问energyID

最佳答案

您正在使用 Angular 的“minifiyable”语法,但未提供 $routeParams 作为参数之一。这一行:

myApp.controller('detailsController', ['$scope', function ($scope,$routeParams) {

应该是:

myApp.controller('detailsController', ['$scope', '$routeParams', function ($scope,$routeParams) {

关于javascript - 无法访问我的 angularjs Controller 中的 $routeParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31367918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com