0

I'm using node.js to host my angular website. My angular directive is not working properly because it cannot be displayed when I run my website.

Node http server is used to handle the routes. With console.log(req.url) I'm able to see all requests urls, but there isn't one that should look like /app-get.html :

http.createServer((req, res) => { console.log(req.url) if(req.url == '/'){ fs.readFile('./src/index.html', (err, file) => { res.writeHead(200, {'Content-Type': 'text/html'}) res.write(file) res.end() }) } if(req.url == '/angular.min.js'){ fs.readFile('./src/angular.min.js', (err, file) => { res.writeHead(200, {'Content-Type': 'application/javascript'}) res.write(file) res.end() }) } }).listen(9999) 

Can I even use templateUrl in angular directive to load html file without configuring server route for that file (app-get.html)?

app.directive("getApp", function() { return { templateUrl: 'app-get.html' } }) 
6
  • Right, but there isn't such request made to server. I would like to know how angular is making request for template. I hope its the similar as if I would include source of css or script file inside html.
    – adict
    CommentedMar 25, 2019 at 10:39
  • If there is no request, then it likely the directive isn't being instantiated. Check the HTML for typos, missing ng-app directive, incorrect normalization of the directive name, etc. Finally put a console.log in the directive to verify that the directive is being instantiated.
    – georgeawg
    CommentedMar 25, 2019 at 15:26
  • So I made a route after I was able to see request for html file related to angular directive, but the problem is that this directive only works after it is initialised inside main index.html page, in <script> tag. If I try to initialise it inside its own "script.js" file I get error SCRIPT5022: [$injector:modulerr]...
    – adict
    CommentedMar 25, 2019 at 22:20
  • You really should do a res.sendHead(404,"Not found").end() for unknown routes. The method, response.end(), MUST be called on each response. Otherwise the request and its response hangs.
    – georgeawg
    CommentedMar 25, 2019 at 22:38
  • The $injector:modulerr error occurs when a module fails to load due to some exception. The error message should provide additional context. A common reason why the module fails to load is that you've forgotten to include the file with the defined module or that the file couldn't be loaded.
    – georgeawg
    CommentedMar 25, 2019 at 22:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.