如果我通过 ng-class 向元素添加一个类,并尝试通过 angular-element 获取同一个类的存在,它总是返回 false。
请让我知道以下代码有什么问题,
html:
<body ng-app="myApp">
<div ng-controller="myController">
<input type="text" ng-class="{'red':required == true}"/>
<button ng-click="add()">click</button>
</div>
</body>
CSS:
.red {border: 1px solid #ff0000;}
javascript:
var myApp = angular.module("myApp", []);
myApp.controller("myController", function($scope){
var elem = angular.element(document.querySelector('input'));
$scope.required = false;
$scope.add = function(){
$scope.required = true;
console.log(elem.hasClass('red'));
} });