【发布时间】:2015-12-24 03:13:28
【问题描述】:
我正在尝试制定一个指令,该指令应该删除选择的第一个选项。
我正在使用这个 html 来生成选择框:
<select remove-whitespace ng-model="user.encryption">
<option ng-repeat="r in selectButtons" title="{{r.text}}" ng-selected="$first" value="{{r.value}}">{{r.text}}</option>
</select>
这部分代码在我的控制器中用于填充视图中的选择框:
$scope.selectButtons = [
{text: "Clear-Text", value: "no_encryption"},
{text: "MD5", value: "md5_encryption"},
{text: "SHA1", value: "sha1_encryption"},
];
我用这个作为我的指令:
.directive("removeWhitespace", function () {
return{
require: 'ngModel',
link: function (scope, element, attributes, ngModel) {
console.log(element.context);
}
}
});
当我做一个 console.log(element.context);以下上下文出现在我的浏览器控制台中:
【问题讨论】:
标签: javascript angularjs select ionic directive