我怎样才能调用连接codeURIComponent从angularJS模板? [英] How can I invoke encodeURIComponent from angularJS template?

查看:172
本文介绍了我怎样才能调用连接codeURIComponent从angularJS模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的角度JS模板块一拉

I have a block in my angular JS template a la

<a href="#/foos/{{foo.id}}">{{foo.name}}</a>

不过,foo.id属性可以有时含有时髦的字符('/')。我想要做这样的事情:

However, the foo.id property can sometimes contain funky characters ('/'). I want to do something like this:

<a href="#/foos/{{encodeURIComponent(foo.id)}}">{{foo.name}}</a>

但它好好尝试的工作?我该如何解决这个问题?

but it doens't work? How can I fix this?

推荐答案

您可以创建一个过滤器,调用连接codeURIComponent

You could create a filter that calls encodeURIComponent

例如

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

然后做

<a href="#/foos/{{foo.id | encodeURIComponent}}">{{foo.name}}</a>

运行例如: http://jsfiddle.net/YApdK/

这篇关于我怎样才能调用连接codeURIComponent从angularJS模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆