1

当显示.bs.tab 事件(引导 3 事件)发生更改时,角度 2/4 双向绑定失败。

我是角度 2/4 的新手。这是一个错误吗?

http://plnkr.co/edit/jZJ64VhVB6yhAzVblJMk

//our root app component
import {Component, NgModule, VERSION, AfterViewInit} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>Hello {{name}}</h2>
    </div>
    <ul class="nav nav-tabs">
            <li role="presentation" class="active">
                <a class="chart-ind" role="tab" data-toggle="tab">h1</a></li>
            <li role="presentation">
                <a class="chart-ind" role="tab" data-toggle="tab">h2</a></li>
            <li role="presentation">
        </ul>
    <ul class="nav nav-tabs">
            <li role="presentation" class="active">
                <a class="chart-ind1" role="tab" data-toggle="tab">h3</a></li>
            <li role="presentation">
                <a class="chart-ind1" role="tab" data-toggle="tab">h4</a></li>
            <li role="presentation">
        </ul>
        <p id="prevname"></p>
        <p id="aftername"></p>
  `,
})
export class App {
  name:string;
  constructor() {
    this.name = `Angular! v${VERSION.full}`
  }
    ngAfterViewInit(){
        $('a.chart-ind').on('click', this.tabChange.bind(this));
        $('a.chart-ind1').on('shown.bs.tab',this.tabChange.bind(this));
    }
    tabChange(e) : void{
      $('#prevname').text(this.name);
      this.name = $(e.target).text();
      $('#aftername').text(this.name);

    }
}

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App ],
  bootstrap: [ App ]
})
export class AppModule {}

(所有选项卡共享相同的回调,h1,h2 使用 click,h3,h4 使用 shown.bs.tab)

4

0 回答 0