user5406193
user5406193

Reputation:

using ng-class in angular js

I am trying to implement ng-class directive in angular and while doing so am a bit stuck on it..

The below is the code snippet:-

<button ng-class="{discover_premium btn btn-lg:userLogin ==2,discover_connect_btn btn btn-lg:userLogin ==3}" >{{userLogin}}</button>

I am using the following in the controller:-

var currentMember= CurrentUserData.query();
     currentMember.$promise.then(function(response){

        $scope.memberProfile = response.login_member_details;

        var memberProfile = $scope.memberProfile;

         if ($scope.memberProfile.type =="free")
        {
        $scope.userLogin = 2
        }
         else
         {
        $scope.userLogin = 3
         }
        })

So I want to implement different class for different condition..

Please help me out am a newbie..

Thanks a lot

Upvotes: 0

Views: 59

Answers (2)

Alexander Elgin
Alexander Elgin

Reputation: 6956

Simply wrap the class names with single quotes

<button ng-class="{'discover_premium btn btn-lg': userLogin == 2, 'discover_connect_btn btn btn-lg': userLogin == 3}" >{{userLogin}}</button>

Upvotes: 4

jcubic
jcubic

Reputation: 66470

Try this:

<button class="btn btn-lg" ng-class="{'discover_premium': userLogin == 2, 'discover_connect_btn': userLogin == 3}" >{{userLogin}}</button>

Upvotes: 1

Related Questions