這不是字體真棒插件。這是我自己寫的。當我將它添加到AppModule時,它不起作用。由於它不是「我」的已知屬性,因此無法綁定到'fa'
的AppModule
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from "@angular/http";
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app.routing.module';
import { HomeComponent } from './home/home.component';
import { DataModule } from './data/data.module';
import { NavtreeComponent } from './sidebar/navtree.component';
import { JsonifyPipe } from './jsonify.pipe';
import { DebugPipe } from './debug.pipe';
import { PagesModule } from './pages/pages.module';
import { PanelsComponent } from './panels/panels.component';
import { IsolateScrollDirective } from './controls/isolate-scroll.directive';
import { FontAwesomeDirective, FontAwesomeLinkComponent } from './controls/font-awesome.component';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
NavtreeComponent,
JsonifyPipe,
DebugPipe,
PanelsComponent,
IsolateScrollDirective,
FontAwesomeDirective,
FontAwesomeLinkComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule,
DataModule.forRoot(),
PagesModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
字體awesome.component.ts
import { Component, Directive, ElementRef, Input, HostListener, OnInit, HostBinding } from '@angular/core';
import { trigger, state, style, transition, animate } from '@angular/core';
@Component({
selector: 'a[fa]',
template:
`<i [fa]="fa"
[@spinonce]="fa === 'refresh' ? clicked : 0"
(@spinonce.done)="clicked=0"></i>
`,
animations: [
trigger('spinonce', [
//state("void", style({
// transform: 'rotate(0deg)'
//})),
transition('0 => 1', [
animate('1000ms ease-in-out', style({
transform: 'rotate(360deg)'
}))
]),
])
]
})
export class FontAwesomeLinkComponent {
@Input() fa: string;
@Input() class: string;
@HostBinding('class')
get getClass(){
return (this.class || '') + ' fa';
}
@HostBinding('attr.aria-hidden')
get ariaHidden() {
return true
}
@HostListener('click')
onLinkClicked() {
this.clicked++;
}
clicked = 0;
}
@Directive({
selector: 'i[fa]'
})
export class FontAwesomeDirective {
@Input() public fa: string;
@Input() public class: string;
@HostBinding('class')
public get classStr() {
return 'fa fa-' + this.fa + ' ' + (this.class || '');
}
@HostBinding('attr.aria-hidden')
public get ariaHidden() { return true }
constructor() {
}
}
當它被用於
<button class="ui-button" (click)="importOrders()">Import Orders</button>
<div class="status-bar"></div>
<div class="order-list">
<div *ngFor="let item of orders" class="success-{{item.success}}">
<div class="icon-block"><i [fa]="item.icon"></i></div>
<span>{{item.order.email}}</span>
</div>
</div>
錯誤
Can't bind to 'fa' since it isn't a known property of 'i'. ("">
<div *ngFor="let item of orders" class="success-{{item.success}}">
<div class="icon-block"><i [ERROR ->][fa]="item.icon"></i></div>
<span>{{item.order.email}}</span>
</div>
"): ng:///PagesModule/[email protected]:29 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:
Can't bind to 'fa' since it isn't a known property of 'i'. ("">
<div *ngFor="let item of orders" class="success-{{item.success}}">
<div class="icon-block"><i [ERROR ->][fa]="item.icon"></i></div>
<span>{{item.order.email}}</span>
</div>
"): ng:///PagesModule/[email protected]:29
奇數。我無法重現這個問題。 https://plnkr.co/edit/jYhtkDr62cc6P46AGuoT?p=preview – LLai