Angular 角度2:无法加载组件
我正在练习angular2,我正在尝试使用属性指令,但我无法加载组件,我不知道我做错了什么 砰的一声: app.ts:Angular 角度2:无法加载组件,angular,Angular,我正在练习angular2,我正在尝试使用属性指令,但我无法加载组件,我不知道我做错了什么 砰的一声: app.ts: //our root app component import {Component} from 'angular2/core' import {AttributeDirective} from './attributedirective.component' @Component({ selector: 'my-app', providers: [], temp
//our root app component
import {Component} from 'angular2/core'
import {AttributeDirective} from './attributedirective.component'
@Component({
selector: 'my-app',
providers: [],
template: `
<div>
<h2>Hello {{name}}</h2>
<my-attr-directive></my-attr-directive>
</div>
`,
directive: [AttributeDirective]
})
export class App {
constructor() {
this.name = 'Angular2'
}
}
import {Component} from 'angular2/core'
import {HighlightDirective} from './highlight.directive'
@Component({
selector: 'my-attr-directive',
template: `
<div myHighlight>Highlight me</div>
`,
directive: [HighlightDirective]
})
export class AttributeDirective{
console.log("test");
}
import {Directive, ElementRef, OnInit} from 'angular2/core'
@Directive({
selector: '[myHighlight]'
})
export class HighlightDirective implements OnInit{
private _defaultGreen = 'green';
constructor (private _elRef: ElementRef){}
ngOnInit():any{
this._elRef.nativeElement.style.backgroundColor = this._defaultGreen;
}
}
有人能帮我修一下吗?这会修好你的车
export class AttributeDirective{
consturctor(){
console.log("test"); // you can't use console.log directly as you are working with typescript not javascript....
}
}
这会解决你的问题
export class AttributeDirective{
consturctor(){
console.log("test"); // you can't use console.log directly as you are working with typescript not javascript....
}
}
该属性称为
指令
,而不是指令
。您错过了s
。这是你的作品。谢谢!!我注意到了这一点,并在将我的问题发布到这里后进行了更正。但是,我的plunk无效。该属性名为指令
,而不是指令
。您错过了s
。这是你的作品。谢谢!!我注意到了这一点,并在将我的问题发布到这里后进行了更正。然而,我的砰砰声没有起作用。