我想在div元素中显示数据,并在加载页面时突出显示默认的选定项,当我单击未选定的另一项时,选定的项应该更改此项的值$scope.selectedItem属性。
例如,我有这个数据
Item 1
Item 2
//this is the item list
this.$scope.items = items;
//this is the selected item
this.$scope.selectedItem = selectedItem;
//html. I don't know how to design this, since I don't know how to bind the data to div element.
<div></div>
如果我有一个div元素,我如何绑定数据并显示它。从那里,我如何在选择项目时保存所选的值?
对不起,我是Angular.js的新手,所以我现在很困惑。
您可以点击div本身。。像这样的东西:
<div ng-click="clicked('one')">
Item One
</div>
<div ng-click="clicked('two')">
Item Two
</div>
控制器内:
$scope.clicked = function(item) {
$scope.selectedItem = item;
};
您可以使用ng-class
将div装饰为具有hilight。。