app.js
var myapp = angular.module('myapp', ['ui.router']);
itaasContentApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/404');
$stateProvider.state('parent', {
url:'/parent',
templateUrl :'partials/parent.html',
controller:'parentCtrl'
})
.state('parent.child',{
url:'/child',
templateUrl :'partials/child.html',
controller :'childCtrl'
});
parent.html
<div ui-view>
<table data-ng-init='init()'>
</table>
</div>
child.html
<div >
<table data-ng-init='init()'>
</table>
</div>
parentCtrl
app.controller('parentCtrl', function($scope,$state) {
$scope.init=function()
{
//it will initialize the controller <html data-ng-init='init()'>
}
//I am calling child state
$state.go("parent.child");
});
childCtrl
app.controller('childCtrl', function($scope,$state) {
$scope.init=function()
{
//it will initialize the controller <html data-ng-init='init()'>
}
});
问题: 在加载子状态init方法时,父init方法也调用
父母的init() 然后 孩子的init()
你可以解释一下我做错了吗