我已经在CustomHttp 中读取了Access EventEmitter Service等问题,其中用户在其服务中使用了EventEmitter,但是他在本评论中建议他 不要使用它,而是直接在他的服务中使用Observables.
我还阅读了这个 问题 ,解决方案建议将EventEmitter传递给子节点并订阅它.
我的问题是:我应该,还是不应该手动订阅EventEmitter?我该怎么用?
我试图从一个文件导入组件另一个根组件文件.它给出了错误..
zone.js:484未处理的Promise拒绝:模板解析错误:'courses'不是已知元素:1.如果'courses'是Angular组件,则验证它是否是此模块的一部分.2.如果"courses"是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到此组件的"@NgModule.schema"以禁止显示此消息.("
我的第一个Angular 2 App
[错误 - >]"):AppComponent @ 0:31;区域:;任务:Promise.then;值:错误:模板解析错误:(...)错误:模板解析错误:'courses'不是已知元素:
我的app.component.ts就像[根组件文件]
import { Component } from '@angular/core';
import {CoursesComponent} from './courses.component';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1><courses></courses>',
directives:[CoursesComponent],
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)
和我的courses.component.ts是;
import { Component } from '@angular/core';
@Component({
selector: 'courses',
template: '<h1>courses</h1>'
})
export class CoursesComponent { }
Run Code Online (Sandbox Code Playgroud)
从app.component中的courses.component.ts文件导入课程组件时,我无法在其中声明指令 @Component{}
directives:[CoursesComponent]
给我错误
请告知解决方案.
我是Angular 2的初学者,我正在使用最终的Angular 2发行版.我有一个奇怪的问题.这是我的databinding.component.ts代码:
import { Component } from '@angular/core';
import {PropertyBindingComponent} from './property-binding.component';
import {EventBindingComponent} from './event-binding.component';
@Component({
selector: 'fa-databinding',
templateUrl: 'databinding.component.html',
styleUrls: ['databinding.component.css'],
directives: [PropertyBindingComponent, EventBindingComponent]
})
Run Code Online (Sandbox Code Playgroud)
这是我的app.module.ts代码的和平:
import { PropertyBindingComponent } from './databinding/property-binding.component';
import { EventBindingComponent } from './databinding/event-binding.component';
@NgModule({
declarations: [
AppComponent,
OtherComponent,
AnotherComponent,
DatabindingComponent,
PropertyBindingComponent,
EventBindingComponent
]
Run Code Online (Sandbox Code Playgroud)
此代码无法正常工作:
ERROR in [default] /home/tornado/work/first-app/src/app/databinding/databinding.component.ts:11:2
Argument of type '{ selector: string; template: any; styles: any[]; directives: (typeof PropertyBindingComponent | ...' is not assignable to parameter …
Run Code Online (Sandbox Code Playgroud) I'm currently working on adding a CodeMirror editor to a project, an Angular2 project more precisely. But Im' having trouble doing it. The instantiation of my editor doesn't seem to work correctly. My code is the following:
editor.component.ts
import {Component} from 'angular2/core'
import {BrowserDomAdapter} from 'angular2/platform/browser'
declare var CodeMirror: any;
@Component({
selector: 'editor',
templateUrl: './meang2app/partials/editor.html'
})
export class Editor{
dom: BrowserDomAdapter;
editor: any;
constructor(){
this.dom = new BrowserDomAdapter();
this.editor = new CodeMirror.fromTextArea(this.dom.query("textarea"), {lineNumbers: true, mode: {name: "javascript", globalVars: true}});
} …
Run Code Online (Sandbox Code Playgroud)