我正在尝试将属性指令添加到使用 ng-options 的选择中:
<select ng-model="item.Subcategory" ng-options="subcategory.Name as subcategory.Name for subcategory in GetSubcategories(item.Category)" monitor></select>
目前,它没有做任何有意义的事情:
angular.module("monitor", [])
.directive("monitor", function()
{
var directive =
{
restrict: "A",
scope:
{
},
controller: function($scope)
{
console.log("I exist");
}
};
return directive;
});
该指令似乎正在工作,因为我看到使用该指令的每个项目都有一个“我存在”,但它选择丢失了它的选项。
有了指令,我可以在 HTML 中看到它作为选择的唯一选项:
<option value="?" selected="selected"></option>
与此相反,当不使用指令时:
<option value="0" selected="selected">Cats</option>
<option value="1">Dogs</option>
为什么我的指令会破坏 ng-options?
谢谢你。