Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AngularJS中路由到模板时如何调用方法?_Angularjs_Angularjs Service_Route Provider - Fatal编程技术网

在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: {

当路由到AngularJS中的模板时,如何从服务调用方法

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){…