0

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 Answers 2

1

nativescript removes angular module.id so templateUrl requires absolute path which templateUrl: 'app.component.xml', to templateUrl: '../app/YOUR_COMPONENT_DIRECTORY/NAME.component.xml'

Sign up to request clarification or add additional context in comments.

1 Comment

That would work. It's relative to the app folder so you could skip the app part so it becomes more simply: YOUR_COMPONENT_DIRECTORY/NAME.component.html or ./YOUR_COMPONENT_DIRECTORY/NAME.component.html. The preference for the file extension is html as @Houssem mentions as the tooling tends to work better and the ide tends to complain less about your view.
1

In nativescript 2, using ng2, the 'templateUrl' file's extension is in fact a '.html' and not a '.xml'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.