Directives
In AngularJS, we can use a variety of naming conventions to reference directives .
In the AngularJS documentation, all the directive are indexed under their camel-case name
(For example, ngModel). In a template, howeven, we need to use either snake-case form(ng-model),
colon-separated(ng:model) or the underscore-separated(ng_model) form. Addtionally, each reference to
a directive can be prefixed with either x- or data-.

the interpolation directive--- {{}}
and it has an equivalent directive called ng-bind. Usually the ng-bind directive is used to hide
expressions before AngularJS has a chance of processing them on the initial page load.

the interpolation directive will do escaping of any HTML content found in the model in order to prevent
HTML injection attacks. for example :
        $scope.msg="hello,<b>world</b>";
    and the markup fragment:
        <span>{{msg}}</span>
    the result will be <span>hello,&lt;b&gt;world&lt;/b&gt;</span>    
if,for any reason, you model contains HTML markup that needs to be evaluated and rendered by a browser,
you can use the ng-bind-html-unsafe directive to switch off default HTML tags escaping.
        <span ng-bind-html-unsafe="msg"></span>
but, there is also a third option: ng-bind-html. this directive is a compromise between behavior of the
ng-bind-html-unsafe(allow al HTML tags) and the interpolation directive(allow no HTML tags at all).you can
use ng-bind-html where you want to allow some HTML tags.  
    ng-bind-html directive resides in a separate module (ngSanitize) and require inclusion of an addtional
    source file:angular-sanitize.js.
Don't forget to declare dependency on the ngSanitize module if you plan to use the ng-bind-html directive.

Conditional display
Showing and hiding parts of the DOM based on some conditions is a common requirement.
AngularJS is equipped with four different sets of directive fot this occasion(ng-show/ng-hide,
ng-switch-*,ng-if and ng-include)

ng-show/ng-hide
<div ng-show="showSecret"></div>
this div will show when showSecret is true and hide when showSecret is false.

ng-switch-*
If we want to physically remove or add DOM nodes conditionally , the family of ng-switch directives will come
handy:
    <div ng-switch on="showSecret">
        <div ng-switch-when="1">Secret1</div>
        <div ng-switch-when="2">Secret2</div>
        <div ng-switch-default>won't show my secrets!</div>
    </div>

ng-if
Just like other if in other languages,
    <div ng-if="showSecret">Secret</div>

ng-include
The ng-include directive can be used to conditionally display blocks of dynamic, AngularJS-powered markup.
    <div ng-include="user.admin && 'edit.admin.html' || 'editor.user.html'"></div>
ng-include accepts an string as its argument. so it must be something like ng-include=" 'a.html' "

ng-repeat
    $index starts with 0
    $first, $middle,$last return a boolean
using ng-repeat , we can iterate over properties of an object. check the following code:    
    <li ng-repeat="(name,age) in user">
        <span>{{name}} 's  age is {{age}}</span>
    </li>
but in this case, we can't control iteration order.
There is a slight problem with ng-repeat directive: it need a container element to repeat. For example, if I
want to repeat two rows in a table, it must be
    <table>
        <tbody ng-repeat="user in users">
            <tr>{{user.name}}</tr>
            <tr>{{user.age}}</tr>
        </tbody>
    </table>

AngularJs(Part 7)--Build-in Directives的更多相关文章

  1. [译]在AngularJS中何时应该使用Directives,Controllers或者Service

    原文: http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ Services Servic ...

  2. [AngularJS] Using Services in Angular Directives

    Directives have dependencies too, and you can use dependency injection to provide services for your ...

  3. [AngularJS] Using ngModel in Custom Directives

    You can use ngModel in your own directives, but there are a few things you'll need to do to get it w ...

  4. 【转】Build Your own Simplified AngularJS in 200 Lines of JavaScript

    原文:http://blog.mgechev.com/2015/03/09/build-learn-your-own-light-lightweight-angularjs/ Build Your o ...

  5. A Step-by-Step Guide to Your First AngularJS App

    What is AngularJS? AngularJS is a JavaScript MVC framework developed by Google that lets you build w ...

  6. Integrating AngularJS with RequireJS

    Integrating AngularJS with RequireJS When I first started developing with AngularJS keeping my contr ...

  7. [后端人员耍前端系列]AngularJs篇:使用AngularJs打造一个简易权限系统

    一.引言 上一篇博文已经向大家介绍了AngularJS核心的一些知识点,在这篇博文将介绍如何把AngularJs应用到实际项目中.本篇博文将使用AngularJS来打造一个简易的权限管理系统.下面不多 ...

  8. angularjs指令中的compile与link函数详解(转)

    http://www.jb51.net/article/58229.htm 通常大家在使用ng中的指令的时候,用的链接函数最多的是link属性,下面这篇文章将告诉大家complie,pre-link, ...

  9. AngularJs打造一个简易权限系统

    AngularJs打造一个简易权限系统 一.引言 上一篇博文已经向大家介绍了AngularJS核心的一些知识点,在这篇博文将介绍如何把AngularJs应用到实际项目中.本篇博文将使用AngularJ ...

  10. 【转】angularjs指令中的compile与link函数详解

    这篇文章主要介绍了angularjs指令中的compile与link函数详解,本文同时诉大家complie,pre-link,post-link的用法与区别等内容,需要的朋友可以参考下   通常大家在 ...

随机推荐

  1. 牛客小白月赛1 G あなたの蛙は旅⽴っています【DP】

    题目链接 https://www.nowcoder.com/acm/contest/85/G 思路 按照题解上的方式 存取数据 然后DP一下 就可以了 AC代码 #include <cstdio ...

  2. ubuntu14.04 spring cloud config server + gradle搭建

    Server端:在eclipse上,创建Java Project项目.自带的src包删掉手动建文件夹.基础的目录文件都创建上 |--ZSpringCloud|--build.gradle|----sr ...

  3. Python 核心编程 课后习题 第五章

    2. 操作符. (a) 写一个函数, 计算并返回两个数的乘积. (b) 写一段代码调用这个函数, 并显示它的结果. def multi(a,b): return a * b result = mult ...

  4. 利用etcd及confd实现配置自动管理

    ETCD etcd 架设etcd集群 静态启动etcd集群需要每个成员在集群中知道另一个成员.在许多情况下,集群成员的IP可能提前未知.在这种情况下,可以使用etcd集群的自动发现服务.一旦etcd集 ...

  5. 图文了解 Kafka 的副本复制机制

    让分布式系统的操作变得简单,在某种程度上是一种艺术,通常这种实现都是从大量的实践中总结得到的.Apache Kafka 的受欢迎程度在很大程度上归功于其设计和操作简单性.随着社区添加更多功能,开发者们 ...

  6. Hibernate学习---第九节:Hibernate之hql

    一.Hql 入门 1.实体类: package learn.hibernate.bean; import java.util.Date; import java.util.HashSet; impor ...

  7. Flex学习之(JS中调用Flex的方法)

    flex端 public function initApp():void   {    ExternalInterface.addCallback("function1",call ...

  8. java-StringBuffer常用方法

    对字符串进行修改的时候,需要使用可变长字符串StringBuffer 和 StringBuilder 类. append(String s):将指定的字符串追加到此字符序列. Reverse():将此 ...

  9. NodeJS中 Path 模块

    var path = require('path'); // 当发现有多个连续的斜杠时,会替换成一个: 当路径末尾包含斜杠时,会保留: // 在 Windows 系统会使用反斜杠. var p = p ...

  10. aac格式介绍

    AAC编码后数据打包到FLV很简单. 1. FLV音频Tag格式                              字节位置    意义0x08,                       ...