如何在每次访问状态时执行控制器块?
How to make so a controller block is executed everytime a state is accessed?
我有一个连接到状态的控制器,每次访问所述状态时,我都需要我的控制器运行我进行验证的块。
我该怎么做?
每次调用函数时控制器都会执行,例如如下所示的 init() 函数
.controller('test',function($scope){
$scope.init = function( ){
// your code block here
}
$scope.init();
});
为了每次重新加载控制器你应该提到 reload: true
你的选项 .state
ui-router
的声明
示例代码
$stateProvider
.state('state1', {
templateUrl: 'state1.html',
controller: `state1Ctrl`,
reload: true //forcefully reload route and load controller again
})
你也可以参考这个SO Question
为了在每次您的位置发生变化时调用特定函数,您还可以将 html 中的函数定义为:
<div ng-init="allDealerListing()">
因此,每当加载 html 中的特定 div 时,都会自动调用该函数。
因此调用状态函数的变化
我有一个连接到状态的控制器,每次访问所述状态时,我都需要我的控制器运行我进行验证的块。
我该怎么做?
每次调用函数时控制器都会执行,例如如下所示的 init() 函数
.controller('test',function($scope){
$scope.init = function( ){
// your code block here
}
$scope.init();
});
为了每次重新加载控制器你应该提到 reload: true
你的选项 .state
ui-router
示例代码
$stateProvider
.state('state1', {
templateUrl: 'state1.html',
controller: `state1Ctrl`,
reload: true //forcefully reload route and load controller again
})
你也可以参考这个SO Question
为了在每次您的位置发生变化时调用特定函数,您还可以将 html 中的函数定义为:
<div ng-init="allDealerListing()">
因此,每当加载 html 中的特定 div 时,都会自动调用该函数。
因此调用状态函数的变化