Oswaldo Oswaldo - 4 months ago 73
AngularJS Question

ui-router with ControllerAs binding

ui-router State:

$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: 'app/dashboard/dashboard.html',
controller: 'DashboardController as vm'
});


In DashboardController I have:

var vm = this;
vm.title = 'Dashboard';


And in dashboard.html template:

{{vm.title}}


Why the result is showing "{{vm.title}}" instead of bind to it's value in controller?

Answer

There's a controllerAs setting when you configure the state.

$stateProvider
    .state('dashboard', {
        url: '/dashboard',
        templateUrl: 'app/dashboard/dashboard.html',
        controller: 'DashboardController',
        controllerAs: 'vm'
    });

https://github.com/angular-ui/ui-router/wiki

Comments