Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.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更改<;的背景色;td>;_Javascript_Css_Angularjs - Fatal编程技术网

Javascript angularJS更改<;的背景色;td>;

Javascript angularJS更改<;的背景色;td>;,javascript,css,angularjs,Javascript,Css,Angularjs,所以,我只需要像这样的东西:this.style.backgroundColor=red 我怎么用角写这个$scope.style.backgroundColor不起作用,还有其他选择吗 编辑: 为了澄清一些事情,我需要更改单击元素时的颜色。在JS中很容易做到,但现在我需要在angular中动态地做到这一点。所以,是的,我看不出ng style有什么帮助?因为您正在查看演示文稿的更改,所以您可能希望在视图中进行更改,而不是在控制器中进行更改 将允许您分配可动态更改的angularjs类对象 以下

所以,我只需要像这样的东西:this.style.backgroundColor=red 我怎么用角写这个<代码>$scope.style.backgroundColor不起作用,还有其他选择吗

编辑:


为了澄清一些事情,我需要更改单击
元素时的颜色。在JS中很容易做到,但现在我需要在angular中动态地做到这一点。所以,是的,我看不出ng style有什么帮助?

因为您正在查看演示文稿的更改,所以您可能希望在视图中进行更改,而不是在控制器中进行更改

将允许您分配可动态更改的angularjs类对象

以下是文档中的一个示例:

<input type="button" value="set color" ng-click="myStyle={color:'red'}">
<input type="button" value="set background" ng-click="myStyle={'background-color':'blue'}">
<input type="button" value="clear" ng-click="myStyle={}">
<br/>
<span ng-style="myStyle">Sample Text</span>
<pre>myStyle={{myStyle}}</pre>


示例文本 myStyle={{myStyle}}
编辑:

以下是如何根据控制器内的函数调用有条件地应用ng样式:

并且,在控制器功能中:

var$scope.clicked=false;
var ChangeColor=function($index){$scope.clicked=true;}


另外请注意,您也可以有条件地将预定义的样式类应用于ng class()。

您了解过ngStyle吗?只了解一下它@JonCI并不认为这对我有帮助,因为我需要在函数中调用它。像这样:`var ChangeColor=function($index){//change color of element[$index]}`这将是在原始问题中包含的有用信息。。。我将进行编辑以处理新信息。@Neocrome我通过控制器函数调用添加了条件样式应用程序的示例。我希望它能帮上忙。不起作用。。我知道为什么,$index对于我的
元素总是一样的,对象是用ng repeat创建的,所以是的。。有没有办法指定HTML元素索引?像jquery中的$(this).find()?如果不看到代码,很难解决这个问题,但是您应该能够将实例从ng repeat直接传递到函数中。我们有点转向了另一个问题的主题,但是:
将允许您将函数调用为
$scope.doSomething=function(bar){…}