Nativescript angular 2 error while import multiple components

时间:2016-06-05 13:56:00

标签: angular nativescript

When i import 2 components within directives:[] the second component comes with this error File stores.component.xml does not exists.

What Works

When there is only 1 component in directives: [] or use template instead of templateUrl

app.component.ts

import { Component, OnInit } from "@angular/core";
import { Page } from 'ui/page';
import { ChatsComponent } from './chats/chats.component';
import { StoresComponent } from './stores/stores.component';

@Component({
    selector: "my-app",
    templateUrl: 'app.component.xml',
    directives:[ ChatsComponent, StoresComponent ]
})

app.component.xml

<TabView>
  <StackLayout *tabItem="{title: 'Chats'}">
    <chats></chats>
  </StackLayout>

  <StackLayout *tabItem="{title: 'Store'}">
    <stores></stores>
  </StackLayout>
</TabView>

2 个答案:

答案 0 :(得分:1)

nativescript删除了角度module.id,因此templateUrl需要templateUrl: 'app.component.xml',templateUrl: '../app/YOUR_COMPONENT_DIRECTORY/NAME.component.xml'

的绝对路径

答案 1 :(得分:1)

在nativescript 2中,使用ng2,'templateUrl'文件的扩展名实际上是'.html'而不是'.xml'