我想为单选按钮设置一些默认值,根据应选择特定单选按钮的值。为此,我在 (controlDirectives.js) 文件中创建了一个指令 radioControlDir。
function controlDir()
{
return {
transclude: true,
restrict: 'E',
scope: {
ngModel: '=',
queObj: '='
},
link: function (scope, element, attrs)
{
if(angular.isUndefined(scope.ngModel))
{
scope.ngModel = 'Y';
}
}
};
}
scope.queObj._pageAttributes.defaultValue 具有将在 ngmodel 没有值时设置的值。文本和选择的其他指令工作正常。
最佳答案
我认为这只是因为您具有限制值“E”,这意味着元素。
应该是'A'(属性);
并且在 plunker 中,queObj._pageAttributes.defaultValue
是“”,但是对于 radio ,您需要将它设置为该 radio 的值,例如“Y”;
function radioControlDir()
{
return {
transclude: true,
restrict: 'A',
scope: {
ngModel: '=',
queObj: '='
},
link: function (scope, element, attrs)
{
if(angular.isUndefined(scope.ngModel))
{
scope.ngModel = 'Y';
}
}
};
}
关于javascript - 如何在单选按钮上调用指令以在 Angular Js 中设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911343/