以demo project of angular2-mdl为指南,我移植了tab组件,并尝试如下实现:
import { Component } from '@angular/core';
@Component({
selector: 'my-dashboard',
templateUrl: './landing.my.html'
})
export class MyDashboard {
public activeIndex = 0;
public tabChanged({index}): void {
this.activeIndex = index;
}
}
模板是:
<mdl-tabs mdl-ripple mdl-tab-active-index="0" (mdl-tab-active-changed)="tabChanged($event)">
<mdl-tab-panel mdl-tab-panel-title="home">
<mdl-tab-panel-title>
<mdl-icon class="mdl-color-text--primary">home</mdl-icon><span>Home</span>
</mdl-tab-panel-title>
<mdl-tab-panel-content>
<ul>
<li>Stanis</li>
<li>Joffrey</li>
</ul>
</mdl-tab-panel-content>
</mdl-tab-panel>
<mdl-tab-panel mdl-tab-panel-title="something">
<mdl-tab-panel-title>
<mdl-icon class="mdl-color-text--primary">group_work</mdl-icon><span>Ontology</span>
</mdl-tab-panel-title>
<mdl-tab-panel-content>
<ul>
<li>Stanis</li>
<li>Joffrey</li>
</ul>
</mdl-tab-panel-content>
</mdl-tab-panel>
<mdl-tab-panel mdl-tab-panel-title="another">
<mdl-tab-panel-title>
<mdl-icon class="mdl-color-text--primary">list</mdl-icon><span>Cognitive</span>
</mdl-tab-panel-title>
<mdl-tab-panel-content>
<ul>
<li>Robert</li>
</ul>
</mdl-tab-panel-content>
</mdl-tab-panel>
<mdl-tab-panel mdl-tab-panel-title="else">
<mdl-tab-panel-title>
<mdl-icon class="mdl-color-text--primary">call_split</mdl-icon><span>Cognition</span>
</mdl-tab-panel-title>
<mdl-tab-panel-content>
<ul>
<li>Robert</li>
<li>Renly</li>
</ul>
</mdl-tab-panel-content>
</mdl-tab-panel>
<mdl-tab-panel mdl-tab-panel-title="last">
<mdl-tab-panel-title>
<mdl-icon class="mdl-color-text--primary">backup</mdl-icon><span>Streaming</span>
</mdl-tab-panel-title>
<mdl-tab-panel-content>
<ul>
<li>Joffrey</li>
<li>Myrcella</li>
<li>Tommen</li>
</ul>
</mdl-tab-panel-content>
</mdl-tab-panel>
</mdl-tabs>
我正在使用webpack,出现以下错误:
ERROR in [default] home/my-app-ui/src/app/landing.my.ts:10:23
Binding element 'index' implicitly has an 'any' type.
但是应用程序显示了所需的功能,有人能解释一下如何解决这个问题吗?
最佳答案
Useany
or specific type of the variable like(numbers,string,etc)
public tabChanged(index:any): void {
this.activeIndex = index;
}
关于angular - 绑定(bind)元素“索引”隐式具有“任意”类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40745992/