2013-05-31 40 views
0

我想使用templeUrl來啓動這個迷你應用程序,但我無法做到這一點? :(這是簡單的代碼,感謝年的時間!templateUrl使用angularJS與nodeJs ..失敗?

<!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

它不應該是'templateUrl:「hello.html''呢? – raina77ow

+0

@ raina77ow是的,但頁面現在掛斷?....瀏覽器不響應....有趣的是,不要在控制檯中得到任何misstake ..它的加載和加載,我不能關閉選項卡? – YoniGeek

+0

在控制檯中顯示'starting'嗎? '接收請求'? – raina77ow

回答

-2

看你的節點的代碼,你正在做的...

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

可能需要將其更改爲:

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

它不抱怨,但謝謝你;這是正確的語法!順便我解決了這個問題。請閱讀我的評論(上面) – YoniGeek

+0

其實,這是誤導。前面的'/'符號是'request.url'的一部分,如[here](http://nodejs.org/api/http.html#http_message_url)所示。我想知道誰贊成這一點。 – raina77ow