带有 ControllerAs 绑定的 ui-router [英] ui-router with ControllerAs binding
本文介绍了带有 ControllerAs 绑定的 ui-router的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ui-router 状态:
$stateProvider.state('仪表板', {网址:'/仪表板',templateUrl: 'app/dashboard/dashboard.html',控制器:'仪表板控制器作为虚拟机'});
在 DashboardController 中,我有:
var vm = this;vm.title = '仪表板';
在dashboard.html模板中:
{{vm.title}}
为什么结果显示{{vm.title}}"而不是绑定到它在控制器中的值?
解决方案
配置状态时有一个 controllerAs 设置.
$stateProvider.state('仪表板', {网址:'/仪表板',templateUrl: 'app/dashboard/dashboard.html',控制器:'仪表板控制器',控制器为:'vm'});
https://github.com/angular-ui/ui-router/wiki>
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?
解决方案
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
这篇关于带有 ControllerAs 绑定的 ui-router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文