Angular's “controllerAs” not working in routeProvider

后端 未结 4 1301
醉话见心
醉话见心 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:37

    If you work with $scope, you will have to return $scope at the end of the function for the controllerAs syntax to function.

    app.controller('Ctrl', function($scope) {
        $scope.one = 'actual';
    
        // return $scope
        return $scope;
    });
    

    Good Luck.

提交回复
热议问题