小编abh*_*thi的帖子

类正在使用 Angular 功能,但没有装饰。请添加一个显式的 Angular 装饰器

我有这样一些组件CricketComponentFootballComponentTennisComponent等所有这些类有一些共同的特性: -TeamName, teamSize, players等,这是@Input()

现在我创建了一个BaseComponent类,在那里定义了所有这些属性,这个baseComponent类将被板球/足球/网球/等组件扩展。

基础组件.ts

export class BaseComponent {

    @Input() TeamName: string;
    @Input() teamSize: number;
    @Input() players: any;

}
Run Code Online (Sandbox Code Playgroud)

CricketComponent.ts

@Component({
  selector: 'app-cricket',
  templateUrl: './cricket.component.html',
  styleUrls: ['./cricket.component.scss']
})
export class cricketComponent extends BaseComponent implements OnInit {

  constructor() {
    super();
  }

  ngOnInit(): void {
  }

}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

src/app/base-screen.ts:4:14 中的错误 - 错误 NG2007:

类正在使用 Angular 功能,但没有装饰。请添加一个显式的 Angular 装饰器。

typescript angular

63
推荐指数
4
解决办法
3万
查看次数

'ion-header' 不是已知元素 ionic 5

以下是我采取的步骤

  1. 我使用ionic start template blank创建了一个 ionic 5 的新项目
  2. 将 angular 更新为 angular 9
  3. 使用ng g page main创建了一个新的页面模块
  4. 使用延迟加载在 AppRoutingModule 中列出。

我收到以下错误

ERROR in src/app/pages/main/main.page.html:1:1 - error NG8001: 'ion-header' is not a known element:
1. If 'ion-header' is an Angular component, then verify that it is part of this module.
2. If 'ion-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

1 <ion-header>
  ~~~~~~~~~~~~

  src/app/pages/main/main.page.ts:5:16
    5   templateUrl: './main.page.html',
                     ~~~~~~~~~~~~~~~~~~ …
Run Code Online (Sandbox Code Playgroud)

ionic-framework angular

16
推荐指数
3
解决办法
1万
查看次数

以角度动态更改css变量

在我的 angular 项目中,我在这样的顶级styles.scss文件中定义了一些 css 变量。我在很多地方使用这些变量来保持整个主题的一致性。

:root {
  --theme-color-1: #f7f7f7;
  --theme-color-2: #ec4d3b;
  --theme-color-3: #ffc107;
  --theme-color-4: #686250;

  --font-weight: 300
}
Run Code Online (Sandbox Code Playgroud)

如何从app.component.ts动态更新这些变量的值?在 angular 中做到这一点的干净方法是什么?

css typescript css-variables angular

6
推荐指数
2
解决办法
6533
查看次数