2

I have a tag in which I want to apply class when I have no data in my field.

<label class="col-xs-6 btn btn-white" ng-click="checkMultiSelect(vm.settingsObj.customfields_student,val.key)" ng-class="{'active': vm.settings.customfields_student.indexOf(????) == -1 }">

My settings object is like this:

"details": {
    "__v": 0,
    "_id": "58413d990533de0d1a3a4986",
    "customfields_student": [
      ""
    ],
  }
}

Can any one suggest help for me on how I can apply class when it is empty?

2 Answers 2

1

That's the code:

You need to check the length of your array.

 ng-class="{'active': vm.settings.customfields_student.length==0 }"

Here is a working fiddle.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help but how to activate the class when i have no "customfields_student" in db i.e details={};
Please use this: ng-class="{'active': details.customfields_student==undefined }"
1

Use Array.length property, It returns the number of elements in an array.

ng-class="{'active': vm.settings.customfields_student.length == 0 || vm.settings.customfields_student[0].length == 0 }"

If can use String.length property to check the length of first element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.