用AngularJS动态更改css类的属性

前端之家收集整理的这篇文章主要介绍了用AngularJS动态更改css类的属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@ 我搜索但没有找到有关以下的任何答案:

我喜欢通过bootstrap看的例子

<css>
.bs-docs-example {
  background-color: #FFFFFF;
  border: 1px solid #DDDDDD;
  border-radius: 4px 4px 4px 4px;
  ...
}
.bs-docs-example:after {
  background-color: #F5F5F5;
  border: 1px solid #DDDDDD;
  border-radius: 4px 0 4px 0;
  color: #9DA0A4;
  content: "Title";
  ...
}

但是我需要动态更改.bs-docs-example中的内容
如:

<html>
<div class="bs-docs-example" ng-style="content:'{{ title }}';"
     ng-repeat="title in titles">

你认为这是可能吗?如何 ?

感谢提前.

我使用ng-bind-html做了类似的操作,我没有控制内容,所以我修改一个可以处理它的类
var somecolorvar = "#F00";
$scope.mystyles = ".something:after { color: " + somecolorvar + "; }";

<style ng-bind-html="mystyles"></style>

然后你会得到这样的东西

<style>.something:after { color: #F00; }</style>

编辑:您也可以通过css attr()处理上述问题,这将把属性拉入到内容

.something:after {
    display: inline;
    content: '- Value ' attr(value);
}

<div class="something" value="123">this is</div>
<div class="something" value="456">this be</div>

你会看到像:

this is - Value 123
this be - Value 456
原文链接:https://www.f2er.com/angularjs/140377.html

猜你在找的Angularjs相关文章