【问题标题】:Template content doesn't show up after upgrading to Angular 6.1升级到 Angular 6.1 后模板内容不显示
【发布时间】:2019-02-27 09:50:30
【问题描述】:

我的 app.component 得到了模板文件的名称: 客户端/imports/app/app.component.html

Image screenshot

而不是处理我的模板及其内容。

这是我的组件代码:

import { Component, NgZone } from '@angular/core';
import { Location } from '@angular/common';
import { Router } from '@angular/router';
import template from './app.component.html';

@Component({
  selector: 'app-root',
  template,
})
export class AppComponent {
   user: Meteor.User;

   constructor(private router: Router, zone: NgZone, location:Location) {
    Tracker.autorun(() => {
      if (Meteor.user())
      {
         zone.run(() => {
            this.user = Meteor.user();
         });
      }
      else
      {
        this.user = undefined;
      }
    });
  }

 isMenuActive(value)
 {
    return location.pathname.indexOf(value) !== -1;
 }

 isHome()
 {
    return location.pathname == ""
 }
}

知道为什么它似乎不再起作用了吗?

谢谢,

【问题讨论】:

    标签: angular meteor


    【解决方案1】:

    angular 流星编译包的用法改变了 angular 前几个版本。查找信息的地方是编译器存储库本身。有一个示例应用程序。

    https://github.com/Urigo/angular-meteor/tree/master/examples/MeteorCLI/all-in-one

    基本上,你不导入模板,而是通过 templateurl 引用它

    例如

    @Component({
      selector: 'app',
      templateUrl: 'app.component.html'
    })
    

    【讨论】:

      【解决方案2】:

      使用Component 装饰器,如angular component-metadata 文档中所述。

      写这个import template from './app.component.html'; 会出错,因为你的模板html 没有称为template 的成员。

      你可以像这样重写你的装饰器:

      @Component({
        selector: 'app-root',
        templateUrl: './app.component.html'
      })
      

      【讨论】:

      • @billyjoy 当我这样做时,我在构造函数上得到一个无限循环。我真的没有。
      猜你喜欢
      • 2023-03-18
      • 2018-10-25
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多