[英]Angular-ui: Alternate controller syntax for tabs
I'm trying to add angular-ui bootstrap tabs to a simple app, and am having trouble with different versions of controller definitions / scope (i think) 我试图将angular-ui引导选项卡添加到一个简单的应用程序,并且在使用不同版本的控制器定义/范围时遇到麻烦(我认为)
var app = angular.module('plunker', ['ui.bootstrap']);
// works as intended
var TabsDemoCtrl = function ($scope) {
$scope.tabs = [
{ title:'Dynamic Title 1', content:'Dynamic content 1' },
{ title:'Dynamic Title 2', content:'Dynamic content 2', disabled: true }
];
$scope.alertMe = function() {
setTimeout(function() {
alert('You\'ve selected the alert tab!');
});
};
};
// tabs are selectable, but blank
app.controller('ModifiedCtrl', function () {
this.tabs = [
{ title:'Dynamic Title 1', content:'Dynamic content 1' },
{ title:'Dynamic Title 2', content:'Dynamic content 2' }
];
this.test = 'inital test content';
});
This is my fork of the plunkr in the documentation: http://plnkr.co/edit/UekWz89tCzZnRSBnV2cs?p=preview 这是我在文档中的plunkr的分支: http ://plnkr.co/edit/UekWz89tCzZnRSBnV2cs?p=preview
I've messed around with this, but I'm clearly missing something… any suggestions? 我已经搞砸了,但是我显然漏了一些东西……有什么建议吗? TIA
TIA
This SO post was helpful, but I haven't got it working yet… Alternative syntax for angular.module.controller 这篇SO帖子很有帮助,但是我还没有开始工作…… angular.module.controller的替代语法
The problem is in your markup. 问题出在您的标记中。
You're doing ng-controller="ModifiedCtrl as tabs"
then ng-repeat="tab in tabs
. So, tabs
is actually your controller. You want ng-repeat="tab in tabs.tabs"
for it to work. 您正在执行
ng-controller="ModifiedCtrl as tabs"
然后ng-repeat="tab in tabs
。因此, tabs
实际上是您的控制器。您希望ng-repeat="tab in tabs.tabs"
可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.