angular.js - Angular 2 appInjector 导致错误问题
漂亮男人
漂亮男人 2017-05-15 16:53:52
[AngularJS讨论组]

根据 https://angular.io/docs/js/latest/guide/displaying-data.html 一步一步做, 在引用类上出了问题.

TypeScript 编译:

tsc --watch -m commonjs

"compilerOptions": {
    "emitDecoratorMetadata": true,
    "module": "amd",
    "target": "es5"
}

原始代码为:

/// 
import {Component, View, bootstrap, NgFor} from 'angular2/angular2';

@Component({
  selector: 'display',
  appInjector: [FriendsService]
})

@View({
  template: `
  

My name is {{ myName }}

Friends:

  • {{ name1 }}
`, directives: [NgFor] }) class DisplayComponent { myName: string; names: Array; constructor(friendsService: FriendsService) { this.myName = 'Alice'; this.names = friendsService.names; } } class FriendsService { names: Array; constructor() { this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"]; } } bootstrap(DisplayComponent);
漂亮男人
漂亮男人

全部回复(2)
黄舟

把 FriendsService 搬上去就可以了

仅有的幸福

https://github.com/kittencup/angular2-ama-cn/issues/11 有具体的解决方案

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号