UI的路由器ControllerAs结合 [英] ui-router with ControllerAs binding
本文介绍了UI的路由器ControllerAs结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UI路由器状态:
$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: 'app/dashboard/dashboard.html',
controller: 'DashboardController as vm'
});
在DashboardController我有:
In DashboardController I have:
var vm = this;
vm.title = 'Dashboard';
和在dashboard.html模板:
And in dashboard.html template:
{{vm.title}}
为什么结果显示{{vm.title}},而不是绑定到它在控制器的价值?
Why the result is showing "{{vm.title}}" instead of bind to it's value in controller?
推荐答案
有在配置状态的一个controllerAs设置。
There's a controllerAs setting when you configure the state.
$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: 'app/dashboard/dashboard.html',
controller: 'DashboardController',
controllerAs: 'vm'
});
<一个href=\"https://github.com/angular-ui/ui-router/wiki\">https://github.com/angular-ui/ui-router/wiki
这篇关于UI的路由器ControllerAs结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文