我的角度有問題。當我單獨運行它時,我的角碼代碼正常工作,但是當我使用express在localhost上訪問它時不起作用。會發生什麼是它單獨顯示html文件。 我的服務器代碼: *不能使用快遞的角碼
var express = require('express'),
app = express();
app.get('/', function(req, res) {
res.sendfile('./app/client/main.html');
});
app.listen(3000, function() {
console.log('I\'m listening...');
})
我的角度控制器代碼是
var app = angular.module('tiks', []);
app.controller('mainController', function($scope){
$scope.posts = [];
$scope.newPost = {created_by: '', text: '', create_at: ''};
$scope.post = function(){
$scope.newPost.created_at = Date.now();
$scope.posts.push($scope.newPost);
$scope.newPost = {created_by: '', text: '', created_at: ''};
};
});
和angularised HTML代碼
<!--main.html-->
<!doctype html>
<html>
<head>
<title>Tiks</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="javascripts/tiks.js"></script>
</head>
<body ng-app="tiks">
<div id='main' ng-controller="mainController">
<form ng-Submit="post()">
<input required type="text" placeholder="Your name" ng-model="newPost.created_by" />
<textarea required maxlength="200" rows="3" placeholder="Say something" ng-model="newPost.text"></textarea>
<input class="button" type="submit" value="Chirp!" />
</form>
<div id="post-stream">
<h4>Tiks Feed</h4>
<div class='post' ng-repeat="post in posts | orderBy:'created_at':true" ng-class-odd="'odd'" ng-class-even="'even'">
<p>{{post.created_by}} says {{post.text}} at {{post.created_at}}</p>
</div>
</div>
</div>
</div>
</body>
</html>
請幫助
你沒有告訴快遞服務您的靜態內容https://expressjs.com/en/starter/static-files.html –