javascript - How to show a default value in the view if a data field is empty, in angular.js? -
what best way show placeholder value in view when data field blank, in angular.js?
for example if vm.text
empty, want display - - -
in view. if not empty, show value of vm.text
:
option 1, know accomplish through using ng-show
property:
<div> <span ng-show="!vm.text">- - -</span> <span ng-show="vm.text">{{ vm.text }}</span> </div>
option 2, in controller, set value of vm.text
"- - -"
instead of resetting ""
:
// reset field vm.text = "- - -";
is there another, simpler way in angular.js don't know about?
you can :
<div> <span>{{ vm.text || '- - -' }}</span> </div>
Comments
Post a Comment