我正在使用express js框架。我无法在ejs页面中包含javascript文件。
//这是我的index.ejs页面
<!DOCTYPE html>
<html>`
<head>
<script type='text/javascript' src= "order.js"></script>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body ng-app="myApp" ng-controller="orderCtrl">
<div class="container">
<table class="table table-striped">
<thead><tr>
<th>Item Name</th>
<th>Price</th>
</tr></thead>
<tbody><tr ng-repeat="user in users">
<td>{{ user.fName }}</td>
<td>{{ user.lName }}</td>
</tr></tbody>
</table>
</div>
</body>
</html>
//这是我的JavaScript页面order.js,它应该连接到index.ejs
var app = angular.module('myApp', []);
angular.module('myApp', []).controller('orderCtrl', function($scope) {
$scope.message = 'Hello World!';
$scope.fName = '';
$scope.lName = '';
$scope.passw1 = '';
$scope.passw2 = '';
$scope.users = [
{ fName:'Hege',lName:"Pege" },
{ fName:'Kim',lName:"Pim" },
{ fName:'Sal',lName:"Smith" },
{ fName:'Jack',lName:"Jones" },
{ fName:'John',lName:"Doe" },
{ fName:'Peter',lName:"Pan" }
];
})
我无法在{{user.fName}}显示数据。有人可以帮忙。
答案 0 :(得分:0)
您必须在脚本标记中的头部HTML中包含角度:
<script type='text/javascript' src= "anularpath/angular.js"></script>
你可以在你的情况下使用angular cdn,如果你没有像这样的本地文件:
<head>
<script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.0/angular.min.js"></script>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
并且您应该在关闭body标签之前将order.js文件脚本标记移动到正文的底部。像这样:
<script type='text/javascript' src= "order.js"></script>
</body>
</html>