<script>
var app= angular.module('myApp', ['ngRoute', 'ngResource']);
app.factory('Greeter', ['$resource',function($resource){
return $resource(
'http://123.com/processor-url.php',{
},{
query: {
method:'GET',
/*params: { myvar: myvarActual },*/
isArray:true
}
}
);
}]);
app
.controller('appointmentController', ['$scope', 'Greeter',function($scope,$routeParams,Greeter){
alert($routeParams.myvar);
Greeter.query(function(data) {
$scope.output = data.myvar;
});
}]);
app.controller('homeController', ['$scope', function($scope){
}])
/*Final Config After Loading Everything*/
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/appointments/:myvar', {templateUrl: 'appointments.html', controller: 'appointmentController'});
$routeProvider.when('/home', {templateUrl: 'home.html', controller: 'homeController'});
$routeProvider.otherwise({redirectTo: '/home'});
}]);
</script>
在上面的代码中,似乎控制器甚至无法识别myvar
中包含的routeProvider's myvar
。由于提醒会显示undefined
,而不是myvar
的实际值(即... /appointments/1066
...如果是,我希望$routeParams.myvar = 1066
和{{1}应该是1066
答案 0 :(得分:1)
$routeParams
,所以目前它正在寻找myvar
上不存在的Greeter
......
app
.controller('appointmentController', ['$scope', 'Greeter',function($scope,$routeParams,Greeter){
应该......
app
.controller('appointmentController', ['$scope', '$routeParams', 'Greeter', function($scope, $routeParams, Greeter){