2
我在想如何使用DirectiveResolver
對象來更改給定的Component
。使用DirectiveResolver更改@Component元數據
相關性(NG2動作如此之快,這些天事情就變得過時快速)
"@angular/common": "~2.4.3",
"@angular/compiler": "~2.4.3",
"@angular/core": "~2.4.3",
我已經試過這樣:
import { Component } from '@wwwalkerrun/nativescript-ngx-magic';
import { OnInit, Directive, Type } from '@angular/core';
import { DirectiveResolver } from '@angular/compiler';
class myViewResolver extends DirectiveResolver {
resolve(type: Type<any>, throwIfNotFound?: boolean): Directive {
var view = super.resolve(type, throwIfNotFound);
console.log(type);
console.log(view);
return view;
}
}
@Component({
selector: 'app-root',
templateUrl: 'views/app/app.component.html',
styleUrls: ['views/app/app.component.css'],
providers: [myViewResolver]
})
export class AppComponent {
title = 'app works!';
}
但讓我懷疑解析器是我不明白的日誌沒執行。
有什麼想法?
PS:官方angular.io API文檔中沒有條目...
完美,謝謝 – Sebas
@yurzui:你知道,如果一個人能夠覆蓋'templateUrl's也以這種方式?在'DirectiveResolver'結尾的'view'似乎已經有一個獲取模板的'template'屬性... –
@VolkerRose你的意思是這個https://plnkr.co/edit/IOWpMZDzR3Kjiie0zfKA?p=preview ? – yurzui