지시문을 내 응용 프로그램에서 작동시키는 방법을 알아낼 수 없습니다. 구성 요소에 지시문을 적용하고 싶습니다. 가장 간단한 형식입니다. 지시어가 응용 프로그램에서 작동하지 않습니다.
import {Directive, HostBinding} from '@angular/core';
@Directive({
selector: '[directiveSelector]'
})
export class FirstDirective {
@HostBinding() innerText = 'not working';
}
...
import {Component} from '@angular/core';
@Component({
selector: 'home',
template: `
<h1 directiveSelector>Test</h1>`
})
export class HomeComponent {
}
...
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HomeModule } from "./home/home.module";
import { FirstDirective } from './directives/first.directive';
@NgModule({
imports: [
BrowserModule,
HomeModule
],
declarations: [
AppComponent,
FirstDirective
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
사람이 내가 여기에 놓친 거지 무엇을 알고 있나요? 홈 렌더링은 잘되고 모듈에 래핑 된 구성 요소입니다. 또한, 지시문에서 발사하는 디버거 나 경고를 얻을 수 없습니다 - 템플릿 바인딩에 문제가있을 수 있습니까?
괄호가 필요하지 않습니다.'@HostBinding() innerText;'? 사이트를 방문 할 때 콘솔이나 콘솔에 경고/오류가 표시됩니까? – jonrsharpe
아니요, 오류가 없습니다. 나는 지시가 전혀 달리고 있다고 생각하지 않는다. 그리고 나는 확실하지 않다 왜. 예, 괄호가 붙어 있습니다. 붙여 넣기하는 동안 잃어버린 것임에 틀림 없습니다. – userqwert