How can I invoke encodeURIComponent from angularJS template?

前端 未结 3 1057
逝去的感伤
逝去的感伤 2020-12-03 07:02

I have a block in my angular JS template a la

{{foo.name}}

However, the foo.id property can s

3条回答
  •  离开以前
    2020-12-03 07:17

    You could create a filter that calls encodeURIComponent

    E.g.

    var app = angular.module('app', []);
    app.filter('encodeURIComponent', function() {
        return window.encodeURIComponent;
    });
    

    Then do

    {{foo.name}}
    

    Running example: http://jsfiddle.net/YApdK/

提交回复
热议问题