我正在使用ui-select创建多文本框指令,并且从网站/记事本等复制数据时数据粘贴不正确。任何想法如何修复以下代码。我正在使用Angular 1.3.17和ui-select 0.19.8版本。
指令定义:
(function () {
'use strict';
angular
.directive('Multitextbox', Multitextbox);
Multitextbox.$inject = ['state', 'length'];
function Multitextbox(state, length) {
return {
restrict: 'E',
replace: true,
scope: {
id: '@',
label: '@',
info: '@',
attributeName: '@',
value: '=model',
form: '=',
prop: '@',
baseTag: '='
},
controller: function($scope) {
$scope.model = {value: $scope.value || []};
$scope.pasteTag = false;
$scope.$watch('model.value', function() {
$scope.model.value = $scope.model.value || [];
$scope.value = $scope.model.value;
});
$scope.$watch('value', function(value){
$scope.model = { value : value };
});
var setState = function(result) {
$scope.state = result;
};
$scope.$on('$localeChangeSuccess', function() {
state.get($scope.attributeName).then(setState);
});
$scope.tagTransform = function (newTag) {
var tag = {};
//JSON.parse(JSON.stringify($scope.baseTag));
angular.extend(tag, $scope.baseTag);
// var tag = $scope.baseTag;
if(newTag.toString().length>$scope.maxLength){
newTag = newTag.toString().substr(0,$scope.maxLength);
}
tag[$scope.prop] = newTag;
return tag;
};
}
};
}
})();
Directive Template :
<ui-select id="{{id}}" name="{{id}}" class="form-control" multiple tagging="tagTransform" tagging-label="false" ng-model="model.value" >
<ui-select-match placeholder="Add one...">
<span data-toggle="tooltip" data-placement="bottom" title="{{$item[prop]}}">
<span ng-bind-html="$item[prop].toString() | limitText:true:16:'...'"></span>
</span>
</ui-select-match>
<ui-select-choices repeat="item in model.value">
<div>{{item[prop]}}</div>
</ui-select-choices>
</ui-select>
当我尝试粘贴其他来源的数据时,由于我无法在文本框中看到该值,因此将其视为null / empty。