nuclear_kote
@nuclear_kote

Почему не работает директива-атрибут?

Есть модуль core.module.ts:
import { NgModule } from '@angular/core';
import { TestDirective } from './test/test-directive';
import { Test } from './test/component';

@NgModule({
    declarations: [
        Test,
        TestDirective
    ],
    exports: [
        Test,
        TestDirective
    ]
})
export class CoreModule {
}


test-component.ts:
import { Component } from '@angular/core';

@Component({
    selector: 'test',
    template: 'test'
})
export class Test {
}


test-direcive.ts:
import { Directive } from "@angular/core";

@Directive({
    selector: '[myTest]'
})
export class TestDirective{
}


header.module.ts:
@NgModule({
    imports: [
        CoreModule
    ],
    declarations: [
       AppComponent
    ]
...


template.html:
<test></test> <a href="/hello" [myTest]>hello</a>

Так вот, test нормально работает и выводит свой шаблон, а стоит добавить атрибут [myTest] получаю ошибку:
Unhandled Promise rejection: Template parse errors:
Can't bind to 'myTest' since it isn't a known property of 'a'.


что я делаю не так?
  • Вопрос задан
  • 275 просмотров
Решения вопроса 1
nuclear_kote
@nuclear_kote Автор вопроса
Вообщем похоже ему для работы обязательно нужно @input поле.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы