如果请求为假,我在如何切换类时遇到了一些问题。让我向您展示我的代码和解释。
这就是我输入的样子
<div class="form-group">
<label for="locationName">Location name</label>
<input type="text" class="form-control" id="locationName"
ng-model="locationName">
</div>
这是我获取响应的 Controller 部分
}).success(function(data, status, headers, config) {
console.log(data, status, headers, config);
}).error(function(data) {
$scope.locationNameError = data.errors.locationName;
});
所以现在我不想在 $scope.locationNameError
设置时实现我的类,所需的输入必须是 form-group has-error
例如,到目前为止,我认为要进行相同的排序,但这行不通
<div ng-if="!locationNameError" class="form-group">
<div ng-if="locationNameError" class="form-group has-error">
我做错了吗?我不想用尽可能少的代码来实现解决方案。感谢您的帮助。
最佳答案
使用ng-class
代替ng-if
:
改变:
<div ng-if="!locationNameError" class="form-group">
<div ng-if="locationNameError" class="form-group has-error">
收件人:
<div ng-class="{'has-error': locationNameError}" class="form-group">
关于javascript - 如果响应为假,则使用 Angular 更改类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37996545/