zoukankan      html  css  js  c++  java
  • [Angular 2] Property Binding

    Property Binding is bind property NOT attribute!

    import {Component, Input, Output, EventEmitter} from 'angular2/core';
    
    @Component({
        selector: 'hero-item',
        styles: [
            '.active {color: red}'
        ],
        template: `
           <li [class.active]="isSelected"
            [attr.aria-label]="hero.name"
            (click)="selectHero(hero)">
                {{hero.name}}
           </li>
        `
    })
    // <li [ngClass]="{active: isSelected}"></li>
    
    export class HeroItem{
        label="This is a super hero";
        isSelected = false;
        @Input() hero ;
        @Output() changed = new EventEmitter();
        constructor(){
    
        }
    
        selectHero(hero){
            this.changed.emit(hero);
            this.isSelected = true;
        }
    }

    So 'class' is attribute on DOM, but 'class.active' is an property.

    'aria-label' is attribute, so need to write like 'attr.aria-label'.

    If you don't like use 'class.active', you can use 'ngClass' as shown in commnets

  • 相关阅读:
    windows cmd 编码
    ARM伪指令
    System.load 和 System.loadLibrary
    用GDB调试程序
    ARM指令集
    ARM寻址方式
    abortion
    Oxford City Jealous Lover
    everyday words
    【转】高效率的C++函数返回值
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5357667.html
Copyright © 2011-2022 走看看