RollerDerby February 2016

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

Answers


Alexander Elgin February 2016

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>


jcubic February 2016

Try this:

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

Post Status

Asked in February 2016
Viewed 3,868 times
Voted 7
Answered 2 times

Search




Leave an answer