第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

等效$編譯(角2)

等效$編譯(角2)

ibeautiful 2019-06-03 13:09:33
等效$編譯(角2)我想手動編譯一些包含指令的HTML。什么是相當于$compile角度2?例如,在角1中,我可以動態(tài)編譯HTML片段并將其附加到DOM中:var e = angular.element('<div directive></div>');element.append(e);$compile(e)($scope);
查看完整描述

3 回答

?
素胚勾勒不出你

TA貢獻1827條經(jīng)驗 獲得超9個贊

角形 2.3.0 (2016-12-07)

要獲得所有詳細信息,請檢查:

在行動中看到這一點:

校長:

1)創(chuàng)建模板
2)創(chuàng)建組件
3)創(chuàng)建模塊
4)編譯模塊
5)創(chuàng)建(和緩存)ComponentFactory
6)使用Target創(chuàng)建一個實例

快速概述如何創(chuàng)建組件

createNewComponent (tmpl:string) {
  @Component({
      selector: 'dynamic-component',
      template: tmpl,
  })
  class CustomDynamicComponent  implements IHaveDynamicData {
      @Input()  public entity: any;
  };
  // a component for this particular template
  return CustomDynamicComponent;}

一種將組件注入NgModule的方法

createComponentModule (componentType: any) {
  @NgModule({
    imports: [
      PartsModule, // there are 'text-editor', 'string-editor'...
    ],
    declarations: [
      componentType    ],
  })
  class RuntimeComponentModule
  {
  }
  // a module for just this Type
  return RuntimeComponentModule;}

如何創(chuàng)建ComponentFactory (并緩存它)

public createComponentFactory(template: string)
    : Promise<ComponentFactory<IHaveDynamicData>> {    
    let factory = this._cacheOfFactories[template];

    if (factory) {
        console.log("Module and Type are returned from cache")

        return new Promise((resolve) => {
            resolve(factory);
        });
    }

    // unknown template ... let's create a Type for it
    let type   = this.createNewComponent(template);
    let module = this.createComponentModule(type);

    return new Promise((resolve) => {
        this.compiler            .compileModuleAndAllComponentsAsync(module)
            .then((moduleWithFactories) =>
            {
                factory = _.find(moduleWithFactories.componentFactories                                
                , { componentType: type });

                this._cacheOfFactories[template] = factory;

                resolve(factory);
            });
    });}

如何使用上述結(jié)果的代碼片段

  // here we get Factory (just compiled or from cache)
  this.typeBuilder      .createComponentFactory(template)
      .then((factory: ComponentFactory<IHaveDynamicData>) =>
    {
        // Target will instantiate and inject component (we'll keep reference to it)
        this.componentRef = this
            .dynamicComponentTarget            .createComponent(factory);

        // let's inject @Inputs to component instance
        let component = this.componentRef.instance;

        component.entity = this.entity;
        //...
    });

包含所有細節(jié)的完整描述讀這里,或觀察工作實例


查看完整回答
反對 回復 2019-06-03
  • 3 回答
  • 0 關注
  • 701 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號