在AngularJS中路由到模板时如何调用方法?
当路由到AngularJS中的模板时,如何从服务调用方法在AngularJS中路由到模板时如何调用方法?,angularjs,angularjs-service,route-provider,Angularjs,Angularjs Service,Route Provider,当路由到AngularJS中的模板时,如何从服务调用方法 wikiApp.config(['$routeProvider', 'faqService', 'newsService', function($routeProvider, faqService, newsService) { $routeProvider .when('/hjem',{ templateUrl: 'partials/homeContent.html', resolve: {
wikiApp.config(['$routeProvider', 'faqService', 'newsService',
function($routeProvider, faqService, newsService) {
$routeProvider
.when('/hjem',{
templateUrl: 'partials/homeContent.html',
resolve: {
newsService.setChosenStory("");
faqService.setChosenFAQ("");
}
})
这不对吗S解析用于将其他参数传递给控制器,例如:
$routeProvider
.when('/a', {
templateUrl: '/tmpl',
controller: 'myCtrl',
resolve: {
someParameter: function(){
return 'konichiva';
}
}
})
.when('/b', {
templateUrl: '/tmpl',
controller: 'myCtrl',
resolve: {
someParameter: function(){
return 'vatashiva';
}
}
});
在myCtrl
中:
wikiApp.controller('myCtrl', function(someParameter){
// if path is "/a" then "konichiva" will be logged
// else if path is "/b" then "vatashiva" will be logged
console.log(someParameter);
});
我不知道resolve是做什么的,btwCool,我也可以将它发送到服务?是否?您可以在控制器中使用以下服务:
wikiApp.controller('myCtrl',function(someParameter,faqService,newservice){…