Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
Typescript 如何恢复html(非生成代码)angular2 RC4的源代码_Typescript_Angular - Fatal编程技术网

Typescript 如何恢复html(非生成代码)angular2 RC4的源代码

Typescript 如何恢复html(非生成代码)angular2 RC4的源代码,typescript,angular,Typescript,Angular,如何获取使用JavaScript在IDE中手动键入的源代码 注意:我使用的是angular2rc4 我尝试使用Reflect.getMetadata获取它,但我发现错误,它无法工作 ///<reference path="../../../node_modules/reflect-metadata/reflect-metadata.d.ts"/>" alert("---- " + Reflect.getMetadata(

如何获取使用JavaScript在IDE中手动键入的源代码

注意:我使用的是
angular2rc4

我尝试使用
Reflect.getMetadata
获取它,但我发现错误,它无法工作

 ///<reference path="../../../node_modules/reflect-metadata/reflect-metadata.d.ts"/>"


    alert("---- " + Reflect.getMetadata('annotations', AppComponent)[0].template);
//”
警报(“---”+Reflect.getMetadata('annotations',AppComponent)[0].template);
我在msg警报中未定义

在index.d.ts中

/// <reference path="globals/core-js/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/node/index.d.ts" />
//
/// 
/// 

您需要为反射元数据库安装打字:

$ typings install reflect-metadata --ambient
? Found reflect-metadata typings for DefinitelyTyped. Continue? Yes
Installing reflect-metadata@~0.0.0 (DefinitelyTyped)...

reflect-metadata
└── (No dependencies)
这样,您就可以使用
Reflect
对象而不会出现编译错误

编辑

要从模板URL加载模板内容,请执行以下操作:

@Component({
  selector: 'my-app',
  templateUrl: 'src/app.html'
})
export class App {
  constructor(private http:Http) {
    let templateUrl = Reflect.getMetadata('annotations', App)[0].templateUrl;
    this.http.get(templateUrl).map(res => res.text()).subscribe(template => {
      console.log('template = '+template);
    });
  }
}

请参阅此plunkr:。

我收到此错误!键入错误!已弃用“环境”标志已弃用。请改用“全局”(我的包.json中有反射元数据)这不会引起任何问题你使用哪种版本的打字?你尝试过全局平面吗?;-)我对此不太了解,但似乎我使用全局我更新了我的答案现在可以了,但我得到了未定义的值,因为我使用模板url有任何方法可以获取模板url的html页面内容谢谢!很高兴听到这个消息!是的,您需要使用Angular2的HTTP支持,但是在
map
回调中,您需要使用
text()
而不是
json()