typescript Angular 2:找不到名称“encodeUri”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41290875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:06:48  来源:igfitidea点击:

Angular 2: Cannot find name 'encodeUri'

angulartypescript

提问by Ole Spaarmann

I'm trying to use http.getto call a remote URL. I append a search string to the base URL. This search string should be URL encoded. But I get this error:

我正在尝试使用http.get来调用远程 URL。我将搜索字符串附加到基本 URL。此搜索字符串应该是 URL 编码的。但我收到此错误:

Cannot find name 'encodeUri'

找不到名称“encodeUri”

How should I import it or make it available? This is a standard Javascript function and I had the same problem trying to use the Javascript's Mathobject.

我应该如何导入或使其可用?这是一个标准的 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);
      });
  }

回答by Stefan Svrkota

Function is called encodeURI(), not encodeUri().

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

You can read more about encodeURI()and other Typescript predefined functions here.

您可以在此处阅读有关encodeURI()其他 Typescript 预定义函数的更多信息。