Below here I uploaded my index.html, package.json, server.js, app.js and MainController.js. After running node server, I am only getting index.html. But index.html requires angular.js, app.js, MainController.js. In my console im getting "GET http://localhost:3000/lib/angular/angular.js" not found error.
Can anyone please help me out with this issue.
//package.json
{
"name": "ng-include",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"body-parser": "^1.17.1",
"consolidate": "^0.14.5",
"express": "^4.15.2",
"html": "^1.0.0",
"swig": "^1.4.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "mehadi",
"license": "UNLICENSED",
"repository": {
"type": "git",
"url": "(https://github.com/mehadi07/JavaScript_Projects/AngularJS/ng-include)"
},
"devDependencies": {}
}
// server.js
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var cons = require('consolidate');
var app = express();
app.engine('html', cons.swig);
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'lib/')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/',function(req,res){
res.render('index');
});
// Binding express app to port 3000
app.listen(3000,function(){
console.log('Node server running @ http://localhost:3000')
});
//app.js
'use strict';
// Declare app level module which depends on views, and components
var app = angular.module('loginApp', []);
enter code here
// MainController.js
app.controller('MainController', function MainController($scope) {
var employees = [
{
name: "Ben",
gender: "Male",
salary: 55000,
city: "London"
},
{
name: "Sara",
gender: "Female",
salary: 68000,
city: "Chennai"
},
{
name: "Mark",
gender: "Male",
salary: 57000,
city: "London"
},
{
name: "Pam",
gender: "Female",
salary: 53000,
city: "Chennai"
},
{
name: "Todd",
gender: "Male",
salary: 60000,
city: "London"
},
];
$scope.employees = employees;
$scope.employeeView= "employeeTable.html";
$scope.employeeList="employeeList.html";
});
//index.html
<!DOCTYPE html>
<html lang="en" ng-app="loginApp" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AngularJS App</title>
<link rel="stylesheet" href="main.css">
</head>
<body ng-controller="MainController">
<div ng-include="'employeeTable.html'"></div>
<br/> Select View:
<select ng-model="employeeView">
<option value="employeeTable.html"> Table </option>
<option value="employeeList.html"> List </option>
</select>
<br/>
<br/>
<div ng-include="employeeView"></div>
<!--Created a scope on controller and shortend the .html format to a normal name
-->
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="app.js"></script>
<script src="MainController.js"></script>
</body>
</html>
via Md Mehadi Hasan Mozumder
No comments:
Post a Comment