2016-06-29 33 views
-1

我正在制作一个angularjs应用程序,其中我使用Express作为后端。我面临的问题是无法在我的Html页面之间切换。善良的帮助,我已经尝试了很多教程,但都没有工作。我想在我提供的路径中一定有一些问题。 这里是我的server.js `使用routeProvider时页面变化没有得到反映在angularjs中

var express = require('express'); 
    var app = express(); 
    var bodyParser = require('body-parser'); 
    var mysql  = require('mysql'); 
    var ejs = require('ejs'); 
    var urlencodedParser = bodyParser.urlencoded({extended:false}); 
    var connection = mysql.createConnection({ 
     host  : 'localhost', 
     user  : 'root', 
     password : '', 
     database : 'test' 

    }); 
    connection.connect(); 
    app.use(express.static('public')); 
    //app.set('views', __dirname + 'views');//this is used because res.render('../template/goto_page_options.html', {values : city}); 
              //was not able to render the view 
    app.set('view engine', 'ejs'); 
    app.use(bodyParser.json()); 

    app.get('/', function(req, res) { 
     var path = require('path'); 
    res.sendFile(path.resolve('../template/login.html')); 
     console.log("WOW"); 
    }) 
    app.get('/home', function(req, res) { 
     var path = require('path'); 
     res.sendFile(path.resolve('../template/home.html')); 
     console.log("home requested"); 
    }) 

` 这是我app.js

app.config(['$routeProvider', function ($routeProvider){ 

$routeProvider 
    .when('/',{ 
     redirectTo: '/login' 
    }) 
    .when('/home',{ 
     templateUrl:'home.html' 
    }) 
    .when('/employee',{ 
     templateUrl:'employee.html' 
    }) 
    .when('/login',{ 
     templateUrl:'login.html' 
    }) 
    .otherwise({ redirectTo: '/login' }); 

}]);

这是我的index.html

<body ng-app="starter"> 
      <div ng-view></div> 
     <script src="http://localhost/try/www/js/app.js"></script> 
     <script src="http://localhost/try/www/js/server.js"></script> 
</body> 

我的目录结构是

templates 
    --login.html 
    --home.hml 
js 
    --app.js 
index.html 
+0

目录里面内在张力结构是哪里的模板文件夹里面 –

+0

文件employee.html哪里是在为refrence $ routeProvider? –

回答

0

在您的index.html,已包含

<script src="http://localhost/try/www/js/server.js"></script> 

但在你的目录结构,没有这样的文件。请在浏览器中查看控制台。会有文件未找到错误。 还没有这样的文件

employee.html 
login.html 
+0

这是一个问题,操作者不应该尝试在客户端HTML中包含'server.js'。但是这不太可能导致所描述的问题 – kazenorin

+0

对不起,我没有提到正确的目录结构。模板 --login.html --home.hml --employee.html --employee.html js --app.js --server.js index.html – sakshi

相关问题