Angular's “controllerAs” not working in routeProvider

后端 未结 4 1298
醉话见心
醉话见心 2021-02-08 17:50

I am trying to use the controllerAs property on a $routeProvider route without any success.

Here is the sample code:

var app =          


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-02-08 18:19

    The controllerAs is an alias for the controller instance, if you would like to use that, you have to store data into the controller instance this instead of $scope:

    app.controller('Ctrl', function($scope) {
      var ctrl = this; // assign to a variable to be consistent when using in the template
      ctrl.one = 'actual';
    });
    

    Example Plunker: http://plnkr.co/edit/r8AYtSKbiLQAaPBPriRp?p=preview

提交回复
热议问题