Code Monkey home page Code Monkey logo

Comments (5)

nshahan avatar nshahan commented on September 7, 2024

It looks like you are going about it right. I made a simple demo, my first guess is that you are missing a directive. Take a look and see if you are missing anything or have a typo hiding somewhere.

A quick example here with a dummy class for tabs

import 'package:angular2/angular2.dart';
import 'package:angular2_components/angular2_components.dart';

class Tab {
  String title;
  String text;
  Tab(this.title, this.text);
}

@Component(
    selector: 'my-app',
    styleUrls: const ['app_component.css'],
    templateUrl: 'app_component.html',
    directives: const [materialDirectives, NgFor],
    providers: const [materialProviders])
class AppComponent {
  List<Tab> tabs = new List<Tab>();
  AppComponent() {
    tabs.add(new Tab('one', 'Text in the first tab'));
    tabs.add(new Tab('two', 'Text in the second tab'));
    tabs.add(new Tab('three', 'Text in the third tab'));
  }
}

HTML template:

<h1>Testing Tabs</h1>
<material-tab-panel>
    <material-tab *ngFor="let tab of tabs" [label]="tab.title">
        <div>{{ tab.text }} </div>
    </material-tab>
</material-tab-panel>

from angular_components.

rwrozelle avatar rwrozelle commented on September 7, 2024

Try this, its not the initial creation, its later update of the tab title:

<h1>Testing Tabs</h1>

<div *ngFor="let tab of tabs">
     <material-input
             label="Tab Title"
             floatingLabel="true"
             [(inputText)]="tab.title">
     </material-input>
    <material-input
            label="Tab Text"
            floatingLabel="true"
            [(inputText)]="tab.text">
    </material-input>
</div>

<material-tab-panel>
    <material-tab *ngFor="let tab of tabs" [label]="tab.title">
        <div>{{ tab.text }} </div>
    </material-tab>
</material-tab-panel>
<br/>
<br/>
<div *ngFor="let tab of tabs">{{tab.title}}</div>

from angular_components.

TedSander avatar TedSander commented on September 7, 2024

This is a valid bug... or at least the documentation needs to be updated to better reflect what is going on. The tab labels are only read at initialization time here:
https://github.com/dart-lang/angular2_components/blob/master/lib/src/components/material_tab/material_tab_panel.dart#L94

Let me see if I can get a fix for you for the next release.

from angular_components.

deftomat avatar deftomat commented on September 7, 2024

Any update? Component is unusable when we want to create tabs dynamically 😞

from angular_components.

TedSander avatar TedSander commented on September 7, 2024

This is going to be more work than I would like thanks to onPush which we want to keep.

In the meantime to unblock you trackBy on the for loop can be used to have the objects change when either title of the tab changes. This will cause the Tab object to change and will reflect the different title.

Something like this:
<material-tab *ngFor="let tab of tabs trackBy titleFn" [label]="tab.title">
in controller
dynamic titleFn(num index, Tab tab) => tab.title;

from angular_components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.