ng-class在Angular Condition

时间:2016-02-09 11:09:17

标签: javascript angularjs ng-class

我有一个HTML,如果我把'颜色'在输入框中,段落必须具有红色背景。我认为我正在使用ng-class,仍然无法让它变红。有人可以帮忙吗?

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>

1 个答案:

答案 0 :(得分:1)

错误在于你的CSS::之后有一个多余的.red

正确的声明是:

.red {background:red}