AngularJS 学习笔记(4)-过滤器,$location

来源:互联网 发布:硬盘修复软件 编辑:程序博客网 时间:2024/06/13 06:24

过滤器用于格式化显示给用户的数据。 它们可以在视图模板,控制器或服务中使用。 AngularJS带有一系列内置过滤器,但也很容易定义自己的过滤器。 模板中的一般语法如下:

{{ expression [| filter_name[:parameter_value] … ] }}

内置过滤器date

格式:

{{ date_expression | date : format : timezone}}
{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}: 2010-10-29 11:40:23 +0800

自定义过滤器

var myApp = angular.module('MyTodoMvc', []);    myApp.filter('name',function () {        return function (input) {            return "名字是"+input;        }    });

$location

locationURLwindow.location使URLURL location服务中,并将更改为$ location将反映到浏览器地址栏中。

常用方法:

$location.path()

1.6以后:

href="#!/active"