templateUrl在nodeJs中使用angularJS失败了吗?

时间:2013-05-31 15:53:09

标签: node.js angularjs

我正在尝试使用templeUrl启动这个迷你应用程序,但我无法制作它? :(这是简单的代码,谢谢你的时间!!

<!DOCTYPE html>
<html ng-app="app">
<head>
    <title></title>
</head>
<body>
    <zippy>
        <input type="text" ng-model="data.message">
    </zippy>

<script type="text/javascript">
    var app = angular.module('app', []);

        app.directive('zippy', function(){
                return{
                    restrict: 'E',
                    templateUrl: hello.html

                }
        });
</script>
</body>
</html>

这是我在控制台中得到的,这是什么意思?我的hello.html和索引一样在同一个文件夹中。

ReferenceError: hello is not defined
    at http://127.0.0.1:1339/index.html:24:34
    at Object.d [as invoke] (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:27:173)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:36:469
    at Array.forEach (native)
    at n (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:6:192)
    at Object.<anonymous> (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:36:438)
    at Object.d [as invoke] (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:28:127)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:29:298
    at Object.c [as get] (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:26:479)
    at r (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js:46:142)

我的node.Js代码很短:

var fs = require('fs');
var http = require('http');
console.log('Starting');
var config = JSON.parse(fs.readFileSync('config.json'));
var host = config.host;
var port = config.port;
var server = http.createServer(function(request, response){

        console.log('Receive request: '+ request.url);
        fs.readFile('public' + request.url, function(error, data){
            if (error){
                response.writeHead(404, {'Content-type' : 'text/plain'});
                response.end('SORRY DUDE');
            }else{
                response.writeHead(200, {'Content-type' : 'text/html'});
                response.end(data);
            }
        });
});

1 个答案:

答案 0 :(得分:-2)

查看您的节点代码,您正在做...

  fs.readFile('public' + request.url)

可能想要将其更改为:

  fs.readFile('public/' + request.url)