加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

解析 – 模板解析错误:无法绑定到’ng-class’,因为它不是Angul

发布时间:2020-12-17 17:56:30 所属栏目:安全 来源:网络整理
导读:参见英文答案 Can’t bind to ‘ng-forOf’ since it isn’t a known native property????????????????????????????????????9个 我试图根据Angular 2.0.0-beta.15中布尔值’isLoginPage’的值,在img属性上有条件地应用CSS样式. html的部分如下: a class="na
参见英文答案 > Can’t bind to ‘ng-forOf’ since it isn’t a known native property????????????????????????????????????9个
我试图根据Angular 2.0.0-beta.15中布尔值’isLoginPage’的值,在img属性上有条件地应用CSS样式. html的部分如下:

<a class="navbar-brand" href="#/">
    <img src="/src/resources/images/logo.png" [ng-class]="{logoStyle:  isLoginPage,navLogoStyle: !isLoginPage}" /></a>

logoStyle和navLogoStyle在css类中提到,并在主html页面中添加.在相应的组件中,我设置了isLoginPage的值,如下所示:

import {Component,Input} from 'angular2/core';
import {NgClass} from 'angular2/common';

@Component({
selector: 'header',inputs: ['isLoginPage'],templateUrl: './header.html',directives: [ROUTER_DIRECTIVES,RouterLink,NgClass]
})
 export class HeaderComponent {
   isLoginPage: boolean;
   constructor(){
    if(condition){
     this.isLoginPage = true;
   }
  }

但是当我试图查看结果时,样式不会应用,并且错误’模板解析错误:
无法绑定到’ng-class’,因为它不是已知的本机属性’.有人可以指导我吗?

解决方法

在Angular2中,解析器现在查找指令的 camelCase名称.因此,在您的情况下,您希望将ng-class更改为ngClass

<img src="/src/resources/images/logo.png" [ngClass]="{logoStyle:  isLoginPage,navLogoStyle: !isLoginPage}" /></a>

You can see the documentation for the implementation here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读