Angular 2:* ngIf,模板解析错误,{{}}效果很好

时间:2017-06-27 15:26:13

标签: html angularjs angular-ng-if

我正在使用Angular版本2.4.1并且我有错误'模板解析错误:(...)'当我运行此代码时: 成分:

import {Component} from '@angular/core';
import {SharedData} from '../student/student.data';

@Component({
    moduleId: module.id.toString(),
    selector: 'sd-toolbar',
    templateUrl: 'toolbar.component.html',
    providers: [SharedData]
})
export class ToolbarComponent {
    var: boolean;
    var2: number;
    constructor(service: SharedData){
        this.var = service.getLog();
        this.var2 = service.getId();
        console.log(this.var);
    }
}

模块代码:

import {NgModule } from '@angular/core';
import {CommonModule} from '@angular/common';
import {ToolbarComponent} from './toolbar.component';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
    imports: [
        CommonModule
    ],
    declarations: [ ToolbarComponent ],
})
class MyComponentModule {}

和Html代码:

<nav class="site-menu">
<ul>
    <li>
        <div *ngIf="!var">
        <div class="notifications">
            <a class="notifications__toggle" data-toggle="notifications" href="#notifications">
                <span class="num">4</span>
            </a>
            <div class="notifications__list">
                <ul>
                    <li><a href="view.html#msgs-1">Ny notifikation på 287530</a></li>
                </ul>
            </div>
        </div>
        </div>
    </li>
html中的

{{var2}}显示效果不错,但是* ngIf存在问题,你们可以帮我解决这个问题吗?

0 个答案:

没有答案