1

i am using atom ide for running the following angular code

<!DOCTYPE html>
<html ng-app="home">
<head>
<title></title>
<meta charset="utf-8" />
 <script src = 
     "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js">
 </script>
<script src ="/controller/sample.js"></script>
<link 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" 
rel="stylesheet">
</head>
<body class="container" ng-controller="designController">
<br/>
<br />
<br />
<div class="row" style="background-color:purple;">
 <font color="white">ellucian University</font>
 </div>
<br/>
<br/>
</body>
</html>

i have another controller sample.js

angular.module('home',[]).controller('designController',function($scope){
$scope.message = "hii";
});

and i have another app.js file to run the server

var express = require('express');
var path    = require("path");
var app= express();

app.get('/',function(req,res){
res.sendFile(path.join(__dirname+'/index.html'));
});
app.listen(3000);
console.log('you are listening to a port 3000');

whenever i run my app.js file i am getting an index.html page but angular is not working in index.html file i am new to nodejs so please help me out. Thanks in advance

Sushma
  • 21
  • 3
  • 9
  • What is not working? the js file not loaded? do you see any error in the network tab or console? – Jai Apr 03 '17 at 06:14
  • Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.3/$injector/modulerr?p0=home&p1=Error%3A%20…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.3%2Fangular.min.js%3A18%3A179) – Sushma Apr 03 '17 at 06:21
  • This is the error i am getting in a network console tab – Sushma Apr 03 '17 at 06:22
  • Don't use the minified version of angular during development: that will allow you to get more helpful error messages. Ad don't use version 1.3.3. The current version is 1.6.x. But anyway, if your web server only serves your index.html, and doesn't serve your JS files, there's no way they can be loaded by the browser. – JB Nizet Apr 03 '17 at 06:46
  • Maybe _index.html_ is not able to include _sample.js_ properly. Try adding `app.use('/controller', express.static(__dirname + '/path/to/controller/folder/'));` before you server index.html. – Ankit Gomkale Apr 03 '17 at 07:02
  • yes you are right. sample.js is not included properly that is confirmed now. but still couldn't solve the issue. please help e – Sushma Apr 03 '17 at 07:22
  • @Sushma Did you fix the issue? If yes how? – node_saini Jun 01 '17 at 16:05
  • Try this method, it works for me. https://stackoverflow.com/a/27464258/5840683 – JoeHsu Aug 10 '17 at 10:24

0 Answers0