In following program, as I type red in the input box, the paragraph must turn red in background. Also, why by default I am getting blue background in paragraph (It should be transparent as model is having null value on page load? Can someone help me ?
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<style>
.red{background:red;}
.blue{background:blue;}
</style>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-model="color" />
<p ng-class="{'red':color==red,'blue':color==blue}">This is a paragraph.</p>
<script>
//1 module declaration
var app = angular.module('myApp', []);
//2 controller declaration
app.controller('myCtrl',function($scope){
//code here
});
</script>
</body>
</html>
ng-class="{'red':color== 'red', 'blue': color== 'blue'}"Demo