我解決它沒有火箭科學,只是做舊的方式。看起來RC4在正確解析類型時遇到了一些麻煩。但由於我是一名軟件開發人員,所有角度相關的「RC東西」在上次都發生了很大的變化,所以很難爲任何RC解決這個問題,所以我決定像這樣做一些老派:
declare var $: any; // <-- yep, that's it
declare var FlipClock: any; // <-- same here
@Component({
selector: 'my-component',
moduleId: module.id,
templateUrl: './template.html',
styleUrls: ['./styles.css']
})
export class MyComponent implements AfterViewInit {
@ViewChild('flipclock') flipClock: ElementRef;
errors: any;
constructor() {
}
ngAfterViewInit() {
$(this.flipClock.nativeElement).FlipClock({ // <-- we must make sure that
clockFace: 'TwentyFourHourClock' // at runtime $ and FlipClock
// exists
});
}
}
提供jQuery和FlipClock在運行時,我們只需要追加在我們index.html
腳本:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My ng2-rc4 app</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="vendor/flipclock/compiled/flipclock.css">
<link rel="stylesheet" href="app/main.css">
</head>
<body>
<my-app>Loading ...</my-app>
<script src="/vendor/jquery/dist/jquery.min.js"></script>
<script src="/vendor/flipclock/compiled/flipclock.min.js"></script>
</body>
</html>
這不涉及到你的問題,但你確定你需要的jQuery與Angular2?它在一起工作不好。 –
是的,我需要一個依賴於jQuery的外部依賴。這很糟糕,但在NG2大會上,目前沒有太多的項目可以使用。但多虧了在這裏提到。 –