Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
Angularjs 在ng attr title的false条件下添加ng模型值_Angularjs - Fatal编程技术网

Angularjs 在ng attr title的false条件下添加ng模型值

Angularjs 在ng attr title的false条件下添加ng模型值,angularjs,Angularjs,如果ng attr title中的条件为false,如何在字符串文本中添加mainCtrl.header.Version HTML <label class="form-control" ng-attr-title="{{mainCtrl.header.Version == 0 ? 'This form has not yet been submitted for approval' : 'This form has been submitted for approval {{mainCt

如果
ng attr title
中的条件为false,如何在字符串文本中添加
mainCtrl.header.Version

HTML

<label class="form-control" ng-attr-title="{{mainCtrl.header.Version == 0 ? 'This form has not yet been submitted for approval' : 'This form has been submitted for approval {{mainCtrl.header.Version}} times'}}">{{mainCtrl.header.Version}}</label>
{{mainCtrl.header.Version}

您可以从JS控制器端实现它。获取一个变量
title
检查
version
是否为0,然后分配所需的标题。如果版本>0,则显示带有标题消息的版本。请考虑下面的代码片段。


{{mainCtrl.header.Version}
var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
var mainCtrl=this;
mainCtrl.header={“版本”:0};
如果(mainCtrl.header.Version==0)
{
mainCtrl.title=“此表单尚未提交审批”;
}
其他的
{
mainCtrl.title=“此表单尚未提交“+mainCtrl.header.Version+”审批”;
}
});

您可以通过调用以下函数来实现:

var-app=angular.module('app',[]);
app.controller('htmlTitle',['$scope','$http',函数($scope,$http){
$scope.mainCtrl={
标题:{
版本:0
}
};
$scope.get_title=函数(){
如果($scope.mainCtrl.header.Version==0){
返回“此表格尚未提交审批”;
}
否则{
return“此表单已提交审批”+$scope.mainCtrl.header.Version+“次”;
}
}
}]);

{{mainCtrl.header.Version}
语法是:

ng-attr-title="{{mainCtrl.header.Version == 0 ? 'This form has not yet been submitted for approval' : 'This form has been submitted for approval ' + mainCtrl.header.Version + ' times'}}"
ng attr title显示给定的字符串,因此必须使用{{expr}。
为了测试表达式,我建议您编写
{{your expression | json}}
以查看结果

此表单尚未提交审批
此表单已提交审批{{mainCtrl.header.Version}}次
@pierreemanuellallemant感谢您提出的解决方案。是否可以只使用ng attr title?
ng attr title=“{mainCtrl.header.Version==0?”“此表单尚未提交审批”:“此表单已提交审批”+mainCtrl.header.Version+“times”}}“
work@PierreEmmanuelLallemant我以前试过,但没用。我刚才又试了一次,成功了!我一定错过了什么。你能把这个作为答复吗?