我有一条文本,例如:“Ram is 24 kg”
这段文字是根据一些计算得出的。这些计算是我在我的 angularjs Controller 中进行的。我想为这些文本提供样式,例如“Ram is”的区域字体和“24 kg”的红色乘以新罗马字体。我如何使用 angularjs 实现此目的
在 javascript 中我们可以使用 innerhtml。但是我如何在 angularjs 中实现它
这是我的示例代码
if(condition)
name = $scope.somevalue1
else if(condition)
name = $scope.somevalue2
else
name = $scope.somevalue3
$scope.resultname = name;
if(condition)
weight = $scope.weightvalue1
else if(condition)
weight = $scope.somevalue2
else
weight = $scope.somevalue3
$scope.resultname = $scope.resultname+" is"+ weight;
if(condition)
mess= $scope.messvalue1
else if(condition)
mess = $scope.messvalue2
else
mess = $scope.messvalue3
$scope.resultname = $scope.resultname+" "+ mess
最佳答案
html
<span id="output"></span>
<section ng-app="myApp">
<article ng-controller="MyCtrl">
<p ng-bind-html="resultname"></p>
</article>
</section>
Controller
angular.module('controllers', []);
angular.module('myApp', ['controllers','ngSanitize']);
angular.module('controllers').controller('MyCtrl', function ($scope){
$scope.resultname= 'Ram is <span class="myStyle">24</span>kg'
});
CSS
.myStyle{
color:red
}
您将需要 ngSanatize js 文件
关于javascript - 如何在angular js中提供字体样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37592984/