templateUrl does not work
See original GitHub issueHi I have been trying to split my app up into templates. I have a component like below
import {Component} from "@angular/core";
@Component({
moduleId: module.id,
selector: "home",
templateUrl: 'home.html'
})
export class HomeComponent {}
This component is in /app/home/home.component.ts And template is here /app/home/home.html
However when i run this i get the error
JS: EXCEPTION: Error: File /data/data/org.nativescript.groceries/files/app/home/home.html does not exist. Resolved from: /data/data/org.nativescript.groceries/files/app/home/home.html
Package.json
{
"name": "Groceries",
"version": "1.0.0",
"description": "A NativeScript-built iOS and Android app for managing grocery lists",
"repository": {
"type": "git",
"url": "https://github.com/nativescript/sample-Groceries.git"
},
"keywords": [
"NativeScript"
],
"author": "TJ VanToll <tj.vantoll@gmail.com> (http://tjvantoll.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/nativescript/sample-Groceries/issues"
},
"homepage": "https://github.com/nativescript/sample-Groceries/groceries",
"nativescript": {
"id": "org.nativescript.groceries",
"tns-ios": {
"version": "2.1.0"
},
"tns-android": {
"version": "2.1.1"
}
},
"dependencies": {
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/platform-server": "2.0.0-rc.3",
"@angular/router": "3.0.0-alpha.7",
"nativescript-angular": "0.2.0",
"tns-core-modules": "2.1.0"
},
"devDependencies": {
"babel-traverse": "6.7.6",
"babel-types": "6.7.7",
"babylon": "6.7.0",
"filewalker": "0.1.2",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.2",
"typescript": "^1.8.10"
},
"scripts": {
"android": "tns run android --emulator --device=android",
"hot:android": "tns livesync android --emulator --watch"
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
angular - templateUrl does not work for me - Stack Overflow
1. Are you sure you have the template in the correct directory? If it is in the same directory as the component it...
Read more >relative templateUrl not working · Issue #5630 - GitHub
This sounds like something related to tsconfig.json and a baseUrl being set somewhere. If you provide a repo we can have a look!...
Read more >AngularJS: `template` vs `templateUrl` | by Aaron Frost | Medium
Both of these solutions have problems. The problems with the first are obvious: if all of your templates in production required a separate ......
Read more >templateUrl angular 4 - Forums - Liferay
Hi, I'm having an issue where I'm unable to load html via templateUrl using relative paths. It seems that loading other objects such...
Read more >path in templateUrl changes to path relative to current file on ...
That will result in a run time error in the app, because when the attribute "moduleId" is present, pathes are interpreted as relative...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @el-davo
As @m-abs has pointed out, the path in templateUrl is relative to your app folder.
However, in your case you ar using
moduleId: module.id,
and moduleId is used to resolve relative paths for your stylesheets and templates as it says in the Angular documentation.So in your case you can try the following solutions: 1.) Do not use moduleId and pass the relative path to your template based on the root app directory (e.g.
templateUrl: 'home/home.html'
)2.) Use moduleId: module.id and pass the path of your template against your component. For example in your case this should work out as expected:
You can find basic sample illustrating this behaviour at this link
Thanks @NickIliev, option 2 works. Feel free to close