【发布时间】:2015-09-04 13:03:44
【问题描述】:
我正在尝试查看用户是否已经订阅了计划,如果是,请选中相应的单选按钮。
我有一组 md 单选按钮,我正在使用 ng-repeat 创建:
<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"。
如何让它识别变量值并将实际表达式解析为真或假?
【问题讨论】:
标签: javascript angularjs material-design