2016-11-02 232 views
1

我如何在angular 1中實現類似元素指令的組件?Nativescript angular 2組件如何?

這是我的代碼,但它不工作:

import {Component} from "@angular/core"; 

@Component({ 
    moduleId: "TestComponent", 
    selector: "TestComponent", 
    template: '<Label text="TEST COMPONENT" textWrap="true"></Label>' 
}) 
export class TestComponentComponent { 
    constructor() { } 
} 

@Component({ 
    selector: "my-app", 
    template: ` 
    <StackLayout> 
     <Label text="TEST"></Label> 

     <TestComponent></TestComponent> 
    </StackLayout> 
    ` 
}) 
export class AppComponent { 
    constructor() { } 
} 

回答

4
import {registerElement} from "nativescript-angular/element-registry"; 
registerElement("third-party-view",() => require("./third-party-view").SimpleTag); 

你可以閱讀更多關於它:https://docs.nativescript.org/angular/plugins/angular-third-party.html

+0

這不是爲我工作。 –

+1

通過將組件添加到@NgModule中的「聲明」來實現它的工作 –

相關問題