Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Angular 2中插入Http而不使用typescript_Javascript_Angularjs_Angular - Fatal编程技术网

Javascript 如何在Angular 2中插入Http而不使用typescript

Javascript 如何在Angular 2中插入Http而不使用typescript,javascript,angularjs,angular,Javascript,Angularjs,Angular,angular团队给出的示例仅展示了如何为typescript注入Http 这个JS的等价物是什么: import {Http, HTTP_PROVIDERS} from 'angular2/http'; 这是: constructor(http: Http) { } 假设您是alpha 49或更高版本(您至少应该是beta.0),并且您正在使用UMD捆绑包,正确的答案是使用ng.http.http和ng.http.http\u提供程序 var App = ng.core.

angular团队给出的示例仅展示了如何为typescript注入Http

这个JS的等价物是什么:

import {Http, HTTP_PROVIDERS} from 'angular2/http';
这是:

constructor(http: Http) { }

假设您是alpha 49或更高版本(您至少应该是beta.0),并且您正在使用UMD捆绑包,正确的答案是使用
ng.http.http
ng.http.http\u提供程序

var App = ng.core.
          Class({
            constructor: [ng.http.Http, function(http) {
              /* Do something with http */
            }]
          });

document.addEventListener('DOMContentLoaded', function() {
  ng.platform.browser.bootstrap(App, [ng.http.HTTP_PROVIDERS]);
});
下面是一个示例。

如果使用ES6(而不是TypeScript),则需要为参数字段创建一个getter:

export class SomeClass {
  constructor(http) {}

  static get parameters() {
    return [[Http]];
  }
}

为什么要注入
HttpFactory
?你链接到的页面中没有提到它。哎呀,打开的选项卡太多了。从错误的那个复制来的。谢谢