2016-12-22 59 views
0

我试图使用http.get来调用远程URL。我将搜索字符串附加到基本URL。这个搜索字符串应该是URL编码的。但我得到这个错误:Angular 2:找不到名称'encodeUri'

Cannot find name 'encodeUri'

我应该如何导入它或使它可用?这是一个标准的Javascript函数,我尝试使用Javascript的Math对象时遇到了同样的问题。

search(term:string):any { 
    let encoded_term:string = encodeUri(term); 
    let url:string = [Config.API_BASE_URL, 'members', 'search', '?q=' + encoded_term].join('/'); 

    return this.http.get(url) 
     .map(res => res.json()) 
     .map(res => { 
     return this.buildPage(res); 
     }); 
    } 

回答

3

函数被调用encodeURI(),不encodeUri()

您可以阅读更多关于encodeURI()和其他Typescript预定义函数here

+3

那么,那是令人尴尬的。谢谢。 –

相关问题