Using 'controller as' with the ui-router isn't working as expected

后端 未结 5 854
耶瑟儿~
耶瑟儿~ 2021-02-02 10:35

I have the following state setup for a page using an abstract state and the controller as syntax:

# Details page route
.state \'title\', 
  url: \'/title\',
  ab         


        
5条回答
  •  终归单人心
    2021-02-02 10:54

    You will have to return this; at the end of your controller function for the controllerAs syntax to work.

    angular.module('title').controller 'Title',
     ['$state', ($state) ->
       this.name = 'Test'
       return this
    

    If you are working with $scope, you'll have to return $scope instead.

    angular.module('title').controller 'Title',
     ['$state','$scope', ($state, $scope) ->
       $scope.name = 'Test'
       return $scope
    

    Good Luck.

提交回复
热议问题