如果请求是假的,如何切换类,我有一些问题。让我给你看我的代码和解释。
所以我的输入就是这样的
<div class="form-group">
<label for="locationName">Location name</label>
<input type="text" class="form-control" id="locationName"
ng-model="locationName">
</div>这是控制器的一部分,我在这里获取响应
}).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">我是不是做错了?我不想用较少的代码来实现解决方案。谢谢你的帮助。
发布于 2016-06-23 16:02:24
使用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">发布于 2016-06-23 16:01:31
使用ng-class指令,而不是有两个ng-if
<div class="form-group" ng-class="{'has-error': locationNameError}" class="form-group">发布于 2016-06-23 16:03:17
吴类很可能是你要找的:
<div data-ng-class="{'has-error': locationNameError}">...</div>
https://stackoverflow.com/questions/37996545
复制相似问题