angularjs - Add CSS class using angular -
i have following on angular controller scope model:
$scope.model = { subscriber: { email: '', name: '' }, notice: { text: '', type: '' } }
i need display p tag whenever notice.text not empty , add css class equal notice.type. have:
<p class="notice" data-ng-bind="model.notice.text" data-ng-if="model.notice.text != ''"></p>
p tag has class "notice". need add class contained in $scope.model.type if defined.
how can this?
side question: there better way show / hide p tag instead of using data-ng-if?
you can use ngclass directive
the ngclass directive allows dynamically set css classes on html element databinding expression represents classes added.
code
ng-class="model.notice.text != '' ? model.notice.type : ''"
Comments
Post a Comment