Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angularjs中的花括号内添加条件?_Javascript_Angularjs - Fatal编程技术网

Javascript 如何在angularjs中的花括号内添加条件?

Javascript 如何在angularjs中的花括号内添加条件?,javascript,angularjs,Javascript,Angularjs,我有一个名为$scope.carname=“Volvo”的变量,在html中,我需要检查carname是否存在,如果存在,我需要显示链接,否则我需要显示一些硬编码的值(test) 下面是我的代码 Html {{carname?:test} 控制器 $scope.carname=“沃尔沃” $scope.link=”https://www.w3schools.com“ 如果 $scope.test ="123" $scope.carname = "Volvo"; HTML: {{test}

我有一个名为
$scope.carname=“Volvo”
的变量,在html中,我需要检查
carname
是否存在,如果存在,我需要显示链接,否则我需要显示一些硬编码的值(
test

下面是我的代码

Html

{{carname?:test}
控制器

$scope.carname=“沃尔沃”

$scope.link=”https://www.w3schools.com“


如果

 $scope.test ="123"
 $scope.carname = "Volvo";
HTML:

{{test}
硬编码值

plunker:

用于使用两个
ng if
表达式

<h1 ng-if="carname"> <a  href='link'>Go here </a>  </h1>
<h1 ng-if="!carname"> {{test}} </h1>

{{test}}

{{}
仅用于文本。使用
ng如果
,请参阅文档您可以在控制器中执行此操作。如果我们可以获得此信息,请帮助我@ushmayosingle???@komal我认为您应该使用两个ng如果,这里您有plunker和您的问题解决方案:
    <div ng-if="carname !== ''">{{test}}</div>
    <div ng-if="carname === ''">hard coded value</div>
<h1 ng-if="carname"> <a  href='link'>Go here </a>  </h1>
<h1 ng-if="!carname"> {{test}} </h1>