ui-router nested route controller isn't being called

后端 未结 3 1442
面向向阳花
面向向阳花 2020-12-17 07:23

I am trying to call a controller which should be linked with the home.category route but it isn\'t being called. What\'s wrong in it?

$statePro         


        
3条回答
  •  忘掉有多难
    2020-12-17 08:13

    Another reason the controller may not be called is if you have multiple views for a state and don't put the controller inside the views object. This is difficult to find because there is no error. It just doesn't get called.

    This controller won't be called:

    .state('home', {
        url: '/',
        controller: function($scope){ $scope.someThings = "some stuff"; },
        views: {
            "view1": {                
                template: '

    {{someThings}}

    ' }, "": { template: '

    Some other stuff

    ' } } })

    The controller must go inside the views object:

    .state('home', {
        url: '/',        
        views: {
            "view1": {                
                template: '

    {{someThings}}

    ', controller: function($scope){ $scope.someThings = "some stuff"; }, }, "": { template: '

    Some other stuff

    ' } } })

提交回复
热议问题