1. 程式人生 > >AngularJS 自定義 filter

AngularJS 自定義 filter

問題:後臺返回新聞json格式資料,新聞標題被UrlEncode了。

解決:

var app = angular.module('mainApp', []);
app.controller('mainCtrl', function ($scope, $http) {

});

自定義filter

app.filter('decodeURI', function () { //可以注入依賴

    return function (text) {
        return decodeURI(text);
    }

});

使用:

{{h.title | decodeURI }}