尝试根据同一行中的另一个值显示来自gridcollection的columnvalue。用户可以选择/更改模态中的值,模态中包含带有值的网格。模态关闭时,值将传回。当时,我想为“也称为”设置一个值:
的HTML:
Also known as: <input type="text" `ng-model="displayValue(displayNameData[0].show,displayNameData[0].value)">`
我在作用域上创建了一个函数,仅在'show'值为true时才选择该值:
$scope.displayValue = function (show, val) {
if (show) {
return val;
}
else {
return '';
}
}
但是,当我关闭模态时,出现错误:
Error: [ngModel:nonassign] Expression 'displayValue(displayNameData[0].show,displayNameData[0].value)' is non-assignable.
plnkr参考:http ://plnkr.co/edit/UoQHYwAxwdvX0qx7JFVW?p=preview
如HackedByChinese所述,您无法将ng-model绑定到函数,因此请尝试如下操作:
<input type="text" ng-if="displayNameData[0].show"
ng-model="displayNameData[0].value">
或者,如果您希望此控件可见,则可以创建指令,向其添加函数$parsers
将根据以下内容设置空值show
:
angular.module('yourModule').directive('bindIf', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
function parser(value) {
var show = scope.$eval(attrs.bindIf);
return show ? value: '';
}
ngModel.$parsers.push(parser);
}
};
});
HTML:
<input type="text" bind-if="displayNameData[0].show"
ng-model="displayNameData[0].value">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句