我可以在ui-router路由中定义哪个函数必须从一个控制器调用特定路由?就像我在控制器中有两个功能,两者都不同。像这样 -
app.controller('mainCtrl',function($scope, $stateParams){
$scope.firstFunction = function () {
$scope.firstVar = 'Hello there';
};
$scope.secondFunction = function () {
$scope.secondVar = 'I am learning Angular JS!';
};
})
我想将firstFunction或secondFunction用于不同的路由,例如 -
adsYogiApp.config([ '$stateProvider','$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app.first', { // for this route i want to use mainCtrl's firstFunction
url: "/firstPage",
templateUrl : 'views/firstpage.html',
controller: "mainCtrl"
})
.state('app.second', { // for this route i want to use mainCtrl's secondFunction
url: "/firstPage",
templateUrl : 'views/firstpage.html',
controller: "mainCtrl"
});
}
]);
我该怎么做?