【发布时间】:2016-05-23 02:08:22
【问题描述】:
我想在指令模板中使用标签输入。在以下示例中,我们在指令模板中使用输入文本框,我想使用tags-input,而不是输入框。请参阅以下代码,指令模板内部
我正在使用Here Use tags-input: <input type="text" ng-model="modeldisplay" ></input>,我想在这里使用标签输入:
为此包括以下库
<script src="http://mbenford.github.io/ngTagsInput/js/ng-tags-input.min.js"></script>
// Code goes here
var app = angular.module("myApp", ['ngTagsInput']);
app.directive("myDirective", function(){
return {
restrict: "E",
template : '<h1>Click to choose!</h1><div class="clkm"'+
'ng-repeat="item in items" ng-click="updateModel(item)">{{item}}</div>' +
'Here Use tag-input: <input type="text" ng-model="modeldisplay" ></input>',
require: 'ngModel',
scope : {
items : "=",
modeldisplay:'= modeldisplay'
},
link : function(scope, element, attrs, ctrl){
scope.updateModel = function(item)
{
ctrl.$setViewValue(item);
scope.modeldisplay = item;
}
}
};
});
app.controller("appCtrl", function($scope){
$scope.items = [1,2,3,4,5,6];
$scope.bar = function(foo) {
$scope.aux = foo;
}
});
【问题讨论】:
标签: javascript html angularjs angular-ui-bootstrap