什么angularjs前pression语法这纳克级 [英] What angularjs expression syntax is this in ng-class

查看:159
本文介绍了什么angularjs前pression语法这纳克级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 AngularJS菜鸟手册有一些code可降低类操纵简单前pression和有约束力的:

The AngularJS Noob Handbook has some code which reduces class manipulation to a simple expression and binding :

<a ng-click="flags.open=!flags.open">...<div ng-class="{active:flags.open}">

然而,什么是前pression在NG-类语法?据我所知,竖线(|)将通过一个过滤器和过滤器可以冒号后传递的参数,但上面的code是做不同的东西。如果右侧的范围变量计算结果为真,那么左边的前pression另有包括它的下降。

However, what is the expression syntax in ng-class? I understand that a vertical bar (|) would pass through a filter and that a filter can be passed parameters after a colon but the above code is doing something different. If the scope variable on the right evaluates to true then the expression on the left is included otherwise it's dropped.

这是具体到纳克级​​的指令?是否有 http://docs.angularjs.org 解释这一些文档?

Is this specific to the ng-class directive? Is there some documentation on http://docs.angularjs.org that explains this?

推荐答案

这是简要提及(太简单地说,在我看来)=htt​​p://docs.angularjs.org/api/ng。指令%3angClass> ngClass 文档。如果你传递一个对象 ngClass ,那么它将应用每个的对象作为一个阶级的元素,如果该键的的的是真实的。例如:

This is mentioned briefly (too briefly, in my opinion) in the ngClass documentation. If you pass an object to ngClass, then it will apply each key of the object as a class to the element if that key's value is true. For example:

$scope.first = true
$scope.second = false
$scope.third = true

<div ng-class="{a: first, b: second, c: third}"></div>

将导致

<div class="a c"></div>

这篇关于什么angularjs前pression语法这纳克级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆