I have variable called $scope.carname = "Volvo"
and in html i need to check carname
is exist or not if exist that time i need to show link otherwise i need to show some hard coded value( test
)
Below is my code
Html
<h1>{{carname ? <a href='link'>Go here </a> : test}}
controller
$scope.carname = "Volvo"
;
$scope.link= "https://www.w3schools.com"
Use to use two ng-if
expressions
<h1 ng-if="carname"> <a href='link'>Go here </a> </h1>
<h1 ng-if="!carname"> {{test}} </h1>
You need to use ng-if
$scope.test ="123"
$scope.carname = "Volvo";
HTML:
<div ng-if="carname !== ''">{{test}}</div>
<div ng-if="carname === ''">hard coded value</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.