无法在本机元素上绑定angular2指令 [英] Can't bind angular2 directive on native element

查看:76
本文介绍了无法在本机元素上绑定angular2指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建一个简单的angular2组件,将指令绑定到本机DOM元素时出现错误.

I try to create a simple angular2 component, and I have an error when binding directive to a native DOM element.

例如:

/// <reference path="../../typings/_custom.d.ts" />

import { Component, View } from 'angular2/angular2';
import { RouterLink } from 'angular2/router';

@Component({
    selector: 'my-component',
    directives: [RouterLink]
})

@View({
    template: `
        <a [router-link]="['/page']">test</a>
    `
})

export class MyComponent {    }

=>无法绑定到"routerLink",因为它不是< a>"的已知属性元素,并且没有具有相应属性的匹配指令.

=> Can't bind to 'routerLink' since it isn't a known property of the '<a>' element and there are no matching directives with a corresponding property.

我做错了什么?

推荐答案

  • 正如@EricMartinez所说,指令"是视图"属性
  • 正如@dSebastien所说,"router-link"成为"routerLink"
  • 就像@ pardeep-jain所说的那样,"angular2/angular2"变成了"angular2/core","View"注释被删除了,不需要键入行
  • 这是正确的代码:

    import { Component } from 'angular2/core';
    import { RouterLink } from 'angular2/router';
    
    @Component({
        selector: 'my-component',
        directives: [RouterLink],
        template: `
            <a [routerLink]="['/page']">test</a>
        `
    })
    
    export class MyComponent {    }
    

    这篇关于无法在本机元素上绑定angular2指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆