How to use enum in Angular 2 templates

后端 未结 2 998
我在风中等你
我在风中等你 2021-02-05 00:37

I am trying to use enum in angularjs 2 templates. Below is my code

@Component({
    selector: \'test\',
    template: `
    &
2条回答
  •  一个人的身影
    2021-02-05 01:07

    SectionType can't be used directly within the template. Either you set it to a property of your component, either you add specify methods to check:

    @Component({
        selector: 'test',
        template: `
          
        `
      })
      export class TestComponent{
        activeSection: SectionType = SectionType.Primary;
        setActiveSection(section: SectionType) {
          this.activeSection = section;
        }
        isPrimarySection(activeSection) {
          return activeSection == SectionType.Primary
        }
     }
    

    or

    @Component({
        selector: 'test',
        template: `
          `
      })
      export class TestComponent{
        activeSection: SectionType = SectionType.Primary;
        setActiveSection(section: SectionType) {
          this.activeSection = section;
        }
        SectionType:SectionType = SectionType;
      }
    

提交回复
热议问题