父状态也在子状态加载时调用

时间:2015-08-25 13:13:47

标签: angularjs angular-ui-router

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()

你可以解释一下我做错了吗

0 个答案:

没有答案