相关疑难解决方法(0)

如何在angular2中使用ngSwitch

从最近两天开始,我试图让ngSwitch在角度2.1.0中工作.但似乎不可能让它发挥作用.

我总是得不到NgSwitch的提供者.以下是我的代码 -

模板 -

<template [ngSwitch]="buttonSelector">
  <a class="btn" [ngClass]="buttonSizeClass" *ngSwitchCase="'link'" href="#">
    <span class="btn__text">
      <ng-content></ng-content>
    </span>
  </a>
</template>
Run Code Online (Sandbox Code Playgroud)

零件 -

import { Component, OnInit, Input } from '@angular/core';


@Component({
  selector: 'app-inked-btn',
  templateUrl: './inked-btn.component.html',
  styleUrls: ['./inked-btn.component.css'],
  inputs: ['buttonSize', 'buttonType', "buttonSelector"]
})
export class InkedBtnComponent implements OnInit {
  public buttonSize: string;
  public buttonType: string;
  public buttonSelector: string;
  public buttonSizeClass: any;

  constructor() { }

  ngOnInit() {
    this.buttonSizeClass = {
      'btn--lg': this.buttonSize === 'large',
      'btn--sm': this.buttonSize === 'small',
      'btn--primary': this.buttonType === 'primary'
    }
  } …
Run Code Online (Sandbox Code Playgroud)

angular

13
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1