AngularJS code不工作的NodeJS [英] AngularJS Code not working with NodeJS

查看:177
本文介绍了AngularJS code不工作的NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的平均堆栈。我尝试了一些pretty基本的HTML有些时候我在浏览器中打开该工作angularJS。但不幸的是code,不再被当我试图用我的服务器的NodeJS以使其正常工作。该index.html的显示,但角部分没有工作了。我的输出就是{{文章}}。你有什么建议吗?

的index.html

 < HTML NG-应用=ibrahimsBlog>  < HEAD>
    < META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= UTF-8>
    <标题> Ibrahims博客< /标题>
    &所述; SCRIPT SRC =htt​​p://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js>&下; /脚本>
    &所述; SCRIPT SRC =app.js>&下; /脚本>
  < /头>  <身体GT;  < D​​IV NG控制器=articleController>
    < D​​IV NG重复=文章中的文章>
      {{文章}}
    < / DIV>
  < / DIV>  < /身体GT;< / HTML>

app.js

  VAR应用= angular.module('ibrahimsBlog',[])
app.controller('articleController',[
'$范围',
功能($范围){
  $ scope.articles = [
    '富',
    '酒吧',
    巴兹
  ];
}]);

和我的pretty基本节点服务器:

  VAR前preSS =要求('前preSS),应用程序=前preSS();app.get('/',函数(REQ,RES){
  res.sendFile(__目录名称+/index.html');
});app.listen(3000,函数(){
  的console.log('服务器侦听端口3000');
});


解决方案

修改 SERVER.JS

  VAR前preSS =要求('前preSS');
VAR应用=前preSS();/ * ================================================ ==========
从公用文件夹服务于静态的index.html
================================================== ========== * /
app.use(如press.static(__目录名称+'/公'));app.listen(3000,函数(){
  的console.log('服务器侦听端口3000');
});

I am new to the MEAN Stack. I tried out something pretty basic in html with some angularJS which is working when I open it in my browser. But unfortunately the code is not working anymore when I try to render it with my nodeJS server. The index.html is shown but the angular part is not working anymore. My output is just {{article}}. Do you have any suggestions ?

index.html

<html ng-app="ibrahimsBlog">

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Ibrahims Blog</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body>

  <div ng-controller="articleController">
    <div ng-repeat="article in articles">
      {{article}}
    </div>
  </div>  

  </body>

</html>

app.js

var app = angular.module('ibrahimsBlog', [])
app.controller('articleController', [
'$scope',
function($scope) {
  $scope.articles = [
    'foo',
    'bar',
    'baz'
  ];
}]);

And my pretty basic node server:

var express = require('express'), app = express();

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

app.listen(3000, function() {
  console.log('Server listening on port 3000');
});

解决方案

Change SERVER.JS to:

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

/* ==========================================================
serve the static index.html from the public folder
============================================================ */
app.use(express.static(__dirname + '/public'));

app.listen(3000, function() {
  console.log('Server listening on port 3000');
});

这篇关于AngularJS code不工作的NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆