简体   繁体   English

ng-class在Angular条件下无法正确渲染

[英]ng-class not rendering properly on Angular Condition

I have an html on which if I put 'color' in the input box, the paragraph must have red background. 我有一个html,如果我在输入框中输入“ color”,则该段落必须具有红色背景。 I think I am using ng-class properly, still not able to get it red. 我认为我正在正确使用ng-class,仍然无法将其变为红色。 Can someone help? 有人可以帮忙吗?

HTML: HTML:

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<style>
.red: {background:red}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<p ng-class="{'red':entry=='color'}"> This is box. </p>
<input ng-model="entry" />
<script>
//Module Declaration
var app = angular.module('myApp',[]);
//Controller Declaration
app.controller('myCtrl',function($scope){
    $scope.entry = "";
});
</script>
</body> 
</html>

The mistake is in your CSS: there is a superfluous : after .red . 错误在您的CSS中:.red之后有一个多余的:

The correct declaration is: 正确的声明是:

.red {background:red}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM