我正在嘗試查看用戶是否已訂閱計劃,如果是,請檢查相應的單選按鈕。md-radio-button無法識別ng-checked
我有一組我要創建與NG-重複MD單選按鈕:
<md-radio-group class="md-primary" ng-model="plan">
<div flex ng-repeat="planInfo in plans" class="plan-options">
<md-radio-button value="{{planInfo._id}}" name="plan" class="md-primary" ng-checked="hasPlanID == planInfo._id" required>
<h2 class="plan-name">{{planInfo.name}}</h2>
<h3 class="plan-price">${{planInfo.price}}</h3>
</md-radio-button>
</div>
</md-radio-group>
我有一個是越來越所有的從數據庫中計劃服務:
//check to see if user already has a plan
MyService.GetPlan(currentUser.username).then(function (response) {
if (response.success) {
//This does resolve correctly
$scope.hasPlanID = response.data.plan;
MyService.GetAllPlans().then(function (response) {
if (response.success) {
//plans display properly
$scope.plans = response.data;
} else {
$log.debug(response.message);
}
});
} else {
$log.debug(response.message);
}
});
注意HTML中的ng-checked屬性。當我查看Chrome的檢查器時,它會精確地吐出你在代碼中看到的內容,ng-checked =「hasPlanID == planInfo._id」。
如何讓它識別變量值並將實際表達式解析爲true或false?
我的回答看起來好像很無聊,謝謝! – sigmapi13
沒問題,我很高興它解決了! – JimmyBoh