简体   繁体   English

无法在ejs文件中包含angular js文件

[英]not able to include angular js file in ejs file

I am using express js framework. 我正在使用express js框架。 I am not able to include javascript file in ejs page. 我无法在ejs页面中包含javascript文件。

//This is my index.ejs page //这是我的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>

//This is my JavaScript page order.js which should connect to index.ejs //这是我的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" }
    ];
 })

I am not able to display the data here {{ user.fName }}. 我无法在此处{{user.fName}}中显示数据。 Could someone please help. 有人可以帮忙。

You have to include angular in your HTML inside the head in a script tag : 您必须在script标签的头部内部HTML中包含angular:

<script type='text/javascript' src= "anularpath/angular.js"></script>

you can use angular cdn in your case if you dont have the file locally like this : 如果您在本地没有这样的文件,则可以使用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>

and you should move your order.js file script tag to the bottom of the body right before you close the body tag. 并且您应该在关闭body标签之前将order.js文件脚本标签移动到body的底部。 like this : 像这样 :

    <script type='text/javascript' src= "order.js"></script>
  </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM