0

I built an angular front-end and am attempting to port it to a Express project, and am having a bit of trouble porting the directives I made.

One of the directives not being found is my navigation elements, which in my index.ejs is:

<navigation></navigation>

The directive in my angularApp.js is:

app.directive('navigation', function() {
  return {
    restrict: 'E',
    templateUrl: 'navigation.html'
  }
});

I'm getting an error: "Error: [$compile:tpload] http://errors.angularjs.org/1.2.26/$compile/tpload?p0=navigation.html

Am I linking the .html incorrectly in my directive? I generated the Express project using Express' generator.

Jonathan Wrona
  • 423
  • 2
  • 7
  • 19
  • 1
    probably it's compiled to navigation.html, have you tried `templateUrl: 'navigation.html'` ? – Ilan Frumer Nov 16 '14 at 22:15
  • possible duplicate of [Stating directive templateUrl relative to root](http://stackoverflow.com/questions/16887018/stating-directive-templateurl-relative-to-root) – Davin Tryon Nov 16 '14 at 22:16
  • @IlanFrumer I just tried that and I get a `GET http://localhost:3000/navigation.html [HTTP/1.1 404 Not Found 3ms]` error – Jonathan Wrona Nov 16 '14 at 22:18
  • @JonathanWrona you said it's in your views folder right?! so put the relative path like so: `templateUrl: '/views/navigation.html'` it's not relative to the js file it's relative to the browser location – Ilan Frumer Nov 16 '14 at 22:19
  • @DavinTryon I just took a look at that link. I'm wondering more how I am supposed to link a directive template when porting angular to express. – Jonathan Wrona Nov 16 '14 at 22:20
  • I'm not sure what you mean by "porting". Express is a web server and the template is a file it is serving. The `templateUrl` property is relative to the root of the web site. So you may need to use the the path `/views/navigation...`. – Davin Tryon Nov 16 '14 at 22:22
  • Sorry about the terminology. I'm very new to MEAN dev. What I mean is that I built an angular.js front-end, and now I'm trying to get that working with Express. – Jonathan Wrona Nov 16 '14 at 22:25
  • I'd recommend first trying to do a raw `GET` for the file. I don't know much about `.ejs` but it probably runs through a view engine and produces `.html` files. In fact, you probably don't need an `.ejs` file unless you want to do some server side rendering. So, I think @IlanFrumer is on the right track with comments above. Try something like `http://localhost:3000/views/navigation.html` to see if you get a response. If you do, then try `/views/navigation.html` for the `templateUrl`. – Davin Tryon Nov 16 '14 at 22:34

0 Answers0