Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

angular常规小语法 #19

Open
Open

Description

1、

ng-src:图片链接
ng-href:地址链接
都是解决原生不能辨识的问题,只有这两个指令后面需要加上表达式的符号{{}},其他指令都是不需要的

2、

$scope 是控制器跟视图之间的纽带
$http 是控制器跟服务器之间的纽带
$rootScope 是控制器跟控制器之间的纽带
根作用域 $rootScope,每个控制器都可以用,是各个控制器scope之间的桥梁。

3、时间戳转换为日期可以使用angular内置的过滤器date

用法:

<div>{{1522378115000|date:"yyyy/MM/dd hh:mm:ss EEEE"}}</div>

4、filter&&orderBy&&limitTo

filter:筛选
orderBy:排序
筛选之后排序,用链式调用
limitTo:分页限制,字符串限制

orderBy:根据某个表达式排列数组,排序
orderBy:"age" 默认是升序
orderBy:"age":true 升序
orderBy:"age":false 降序
orderBy:"age":sort(变量控制)

截取字符串:limitTo超过某个字数之后用...代替
分页效果:limitTo:param1:param2 (截取的长度:截取的起始坐标(索引值))

filter/orderBy/limitTo一般配合ng-repeat使用,都可以支持链式调用

5、只有控制器有作用域$scope,所以自定义过滤器跟自定义服务不能注入$scope

6、自定义过滤器:

自定义过滤器命名尽量不要使用驼峰命名规则,也不要有空格,直接小写名字就行
自定义过滤器要有return值,最后return的是函数

7、服务service:

$location:返回当前页面的URL地址 --> window.location
$http:向服务器发送请求 --> ajax
$timeout:延时器 --> window.setTimeout
$interval:计时器 --> window.setInterval

8、渲染html结构,为了解决安全问题,引入插件或者注入$sce

$sce.trustAsHtml

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /