我已經在角度js中創建了一個定製的單選按鈕組件,它將在我的應用程序中使用。以下是我爲組件編寫的代碼。未定義角度自定義單選按鈕組件中的值
JS
angular.module("customComponent")
.component("ngRadiobutton", {
template:
'<label class="ng-control-radio-button">' +
' <span data-ng-bind="$ctrl.label"></span>' +
' <input type="radio" name="{{$ctrl.group}}" data-ng-model="$ctrl.checked"/>' +
' <div class="ng-control-indicator-radio"></div>' +
'</label>' +
'',
bindings: {
label: '=?',
checked: '=',
group: '@'
},
controller: function() {
var $ctrl = this;
console.log($ctrl.checked); // Data is binding properly at this stage
}
});
HTML
<div data-ng-repeat="radio in vm.radioValues">
<ng-radiobutton label="radio.label " group="group1 " checked="radio.checked"></ng-radiobutton>
</div>
JSON
vm.radioValues = [{ label: 'Value1', checked: true },
{ label: 'Value2', checked:false }
];
我面臨的問題是true and false我設置的值沒有與組件綁定。默認情況下,這個單選按鈕沒有被選中。任何人都可以告訴我我的代碼有什麼問題。
在此先感謝
標籤值是越來越綁定? @Shareer – Aparna
是的。一切工作完美@Aparna – Shareer