我想使用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);
}
});
});
它不應該是'templateUrl:「hello.html''呢? – raina77ow
@ raina77ow是的,但頁面現在掛斷?....瀏覽器不響應....有趣的是,不要在控制檯中得到任何misstake ..它的加載和加載,我不能關閉選項卡? – YoniGeek
在控制檯中顯示'starting'嗎? '接收請求'? – raina77ow