Angular 2:* ngIf - 模板解析错误

时间:2016-11-25 11:42:34

标签: angular

我正在使用Angular版本2.1.2,我有错误'模板解析错误:(...)'当我运行此代码时:

组件html:

<div *ngIf="isLoggedIn">
  <br />
  <div class="valign-wrapper">
    <div class="valign center" style="width:100%">
      <a class="waves-effect waves-light btn">
        <i class="mdi mdi-vk"></i>
        Connect
      </a>
    </div>
  </div>
</div>

组件代码:

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'home',
  templateUrl: 'home.component.html',
  styleUrls: ['home.component.css'],
})

export class HomeComponent {
  isLoggedIn = false;
}

模块:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { HomeComponent } from './home.component';

import { routing } from './home.routes';

@NgModule({
  imports: [
    RouterModule,
    routing
  ],
  declarations: [ HomeComponent ],
})

export class HomeModule {}

但是,如果我在html代码中使用例如&#39; {{isLoggedIn}}&#39;显示的值没有任何错误。

请帮帮我,忘记了什么?

1 个答案:

答案 0 :(得分:2)

@NgModule({
  imports: [
    RouterModule,
    routing,
    CommonModule // <<<< added
  ],
  declarations: [ HomeComponent ],
})