簡體   English   中英

角度2:DynamicComponentLoader數據未綁定到模板

[英]Angular 2: DynamicComponentLoader data not binding to template

我正在使用angular2 API指南中詳細介紹的DynamicComponentLoader,

https://angular.io/docs/ts/latest/api/core/DynamicComponentLoader-class.html

我已將代碼設置為如下所示:

import {Page} from 'ionic-framework/ionic';
import { Component, View, DynamicComponentLoader, Injector } from 'angular2/core';
import { RouteParams } from 'angular2/router';

import { DataService } from '../../services/dataService';
import { Section } from '../../models/section';

@Component ({
    selector : 'itemView',
    template : '<div id="content"></div>'
})

export class ItemView {
    constructor (private dataService : DataService, private _routeParams : RouteParams, dcl: DynamicComponentLoader, injector: Injector) {
        var sectionid = this._routeParams.get ('sectionid');
        var categoryid = this._routeParams.get ('categoryid');
        var itemid = this._routeParams.get ('itemid');

        var views = {product: ItemproductView, dispensor: ItemdispensorView, signage: ItemsignageView, equipment: ItemequipmentView};

        if (categoryid !== null) {
            this.item = dataService.getCategoryItem (sectionid, categoryid, itemid);
        } else {
            this.item = dataService.getItem (sectionid, itemid);
        }

        dcl.loadAsRoot(views[sectionid], '#content', injector);
    }
}



/* ****************** */
//   DYNAMIC VIEWS    //
/* ****************** */


@Component ({
    selector : 'itemproductView',
    templateUrl : 'build/components/item/item-product.html'
})
export class ItemproductView {
    constructor(private dataService : DataService, private _routeParams : RouteParams) {
        var sectionid = this._routeParams.get ('sectionid');
        var categoryid = this._routeParams.get ('categoryid');
        var itemid = this._routeParams.get ('itemid');

        this.item = dataService.getCategoryItem (sectionid, categoryid, itemid);
    }
}

@Component ({
    selector : 'itemdispensorView',
    templateUrl : 'build/components/item/item-dispensor.html'
})
export class ItemdispensorView {
    constructor(private dataService : DataService, private _routeParams : RouteParams) {
        var sectionid = this._routeParams.get ('sectionid');
        var itemid = this._routeParams.get ('itemid');

        this.item = dataService.getItem (sectionid, itemid);
    }
}

@Component ({
    selector : 'itemsignageView',
    templateUrl : 'build/components/item/item-signage.html'
})
export class ItemsignageView {
    constructor(private dataService : DataService, private _routeParams : RouteParams) {
        var sectionid = this._routeParams.get ('sectionid');
        var itemid = this._routeParams.get ('itemid');

        this.item = dataService.getItem (sectionid, itemid);
    }
}

@Component ({
    selector : 'itemequipmentView',
    templateUrl : 'build/components/item/item-equipment.html'
})
export class ItemequipmentView {
    constructor(private dataService : DataService, private _routeParams : RouteParams) {
        var sectionid = this._routeParams.get ('sectionid');
        var itemid = this._routeParams.get ('itemid');

        this.item = dataService.getItem (sectionid, itemid);
    }
}

我在網絡瀏覽器中看到了模板,但是{{item}}沒有綁定在模板中。

我不太確定我要去哪里錯了,將不勝感激。

謝謝,

有一個與使用loadAsRoot有關的已知錯誤。 建議的解決方法是使用loadNextToLocationloadIntoLocation

看到這個答案: 綁定在動態加載的組件中不起作用

希望對您有幫助,蒂埃里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM