「的元素沒有成分的指令」我不能讓角的DynamicComponentLoader在beta.6工作DynamicComponentLoader在Angular2測試:
我已經採取了動態元件裝配from their docs示例代碼,並將其添加到自己的工作起動碼爲plnkr, see here。
下面的代碼:
import {Component, DynamicComponentLoader, ElementRef} from 'angular2/core';
@Component({
selector: 'child-component',
template: 'Child'
})
class ChildComponent {
}
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1><div #child></div>'
})
export class AppComponent {
constructor(dcl: DynamicComponentLoader, elementRef: ElementRef) {
dcl.loadIntoLocation(ChildComponent, elementRef, 'child');
}
}
這裏是堆棧跟蹤,它說: 「有一個在單元沒有成分的指令」:
EXCEPTION: Error during instantiation of AppComponent!.BrowserDomAdapter.logError @ angular2.dev.js:23083
angular2.dev.js:23083 ORIGINAL EXCEPTION: There is no component directive at element [object Object]BrowserDomAdapter.logError @ angular2.dev.js:23083
angular2.dev.js:23083 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:23083
angular2.dev.js:23083 Error: There is no component directive at element [object Object]
at new BaseException (angular2.dev.js:7351)
at AppViewManager_.getNamedElementInComponentView (angular2.dev.js:6441)
at DynamicComponentLoader_.loadIntoLocation (angular2.dev.js:12375)
at new AppComponent (run.plnkr.co/mk31ybnwEtsiX31r/app/app.component.ts!transpiled:33)
at angular2.dev.js:1420
at Injector._instantiate (angular2.dev.js:11459)
at Injector._instantiateProvider (angular2.dev.js:11395)
at Injector._new (angular2.dev.js:11385)
at InjectorInlineStrategy.instantiateProvider (angular2.dev.js:11149)
at ElementDirectiveInlineStrategy.init (angular2.dev.js:9081)BrowserDomAdapter.logError @ angular2.dev.js:23083
angular2.dev.js:23083 ERROR CONTEXT:BrowserDomAdapter.logError @ angular2.dev.js:23083
angular2.dev.js:23083 _ContextcomponentElement: nullelement: my-appinjector: Injector__proto__: _ContextBrowserDomAdapter.logError @ angular2.dev.js:23083
angular2-polyfills.js:1152 DEPRECATION WARNING: 'dequeueTask' is no longer supported and will be removed in next major release. Use removeTask/removeRepeatingTask/removeMicroTask
非常好,謝謝! – Hoff
您是否介意更新您的示例代碼以反映API更改? – bodine
@bodine完成! –