I want to change the class name of div using angularjs (app.js) I followed this answer but the class name is not changing in my view.
Here is my view
<div ng-class="class">{{class}}</div>
<button ng-click="changeClass()">Change Class</button>
Here is my app.js
var app = angular.module('myApp', ['ngRoute', 'ngAnimate', 'toaster']);
app.controller("myApp", function ($scope) {
$scope.class = "red";
$scope.changeClass = function () {
alert('a');
if ($scope.class === "red")
$scope.class = "blue";
else
$scope.class = "red";
};
});
app.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/', {
title: 'Dashboard',
templateUrl: 'views/dashboard.html',
controller: 'authCtrl',
role: '0'
})
.otherwise({
redirectTo: '/login'
});
}
])
.run(function ($rootScope, $location, Data) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
var nextUrl = next.$$route.originalPath;
if (localStorage.getItem("serviceUserId") === null) {
$location.path("/login");
} else {
if (nextUrl == '/') {
$location.path("/dashboard");
}
}
});
});
What is the mistake i am doing and how can i fix it ?