N
N
nuclear_kote2016-09-26 15:08:42
Angular
nuclear_kote, 2016-09-26 15:08:42

Why doesn't the attribute directive work?

There is a core.module.ts module:

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-directive.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>
So, test works fine and displays its template, but if I add the [myTest] attribute, I get an error:
Unhandled Promise rejection: Template parse errors:
Can't bind to 'myTest' since it isn't a known property of 'a'.

what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nuclear_kote, 2016-09-26
@nuclear_kote

In general, it looks like it needs an @input field to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question