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' } })
ng-app
directive, incorrect normalization of the directive name, etc. Finally put aconsole.log
in the directive to verify that the directive is being instantiated.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.