【发布时间】:2015-09-08 12:08:21
【问题描述】:
我想在不需要 node 或 express 的情况下在 linux 机器上运行 angular。我已经创建了一个网站,但不确定是什么技术,哈哈。我假设我有一个使用快速服务器的简单 Web 服务器,请参见下面的代码。
var express = require ('express');
var app = express();
var path = require('path');
app.use(express.static(__dirname + '/'));
app.listen(8080);
console.log('Magic happens on port 8080');
我使用节点服务器命令启动它。其余代码是angular-ui。
我是否需要使用 express(并将其托管在节点兼容的服务器上),或者我可以在没有 express 的 linux 机器上运行这个东西吗?如果是这样,我是否需要用其他东西替换我的 server.js 文件(上面)?或者...目前它不能在 linux 机器上工作,但在本地工作得很好。
**编辑:我在共享服务器上测试了一个有角度的“hello world”应用程序,它运行良好。当我在共享服务器上运行完整的 Angular 应用程序时,出现以下错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module routerApp due to:
Error: [$injector:nomod] Module 'routerApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
** 编辑:在回答@RobertMoskal 下面的问题时,在共享服务器上运行的角度hello world 测试基本上是这样的:
<input ng-model="name" type="text" placeholder="Type a name here">
<h1>Hello {{ name }}</h1>
而真正的app基本上是这样的,在html中使用ui-view和ng-repeat:
var routerApp = angular.module('routerApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/home');
$locationProvider.html5Mode(false).hashPrefix("");
$stateProvider
// HOME STATES AND NESTED VIEWS ========================================
.state('home', {
url: '/home',
templateUrl: 'partial-home.html',
// onEnter: scrollContent
})
// ANIMATION AND NESTED VIEWS ========================================
.state('animation', {
url: '/animation',
templateUrl: 'partial-anim.html',
controller: function($scope) {
$scope.animations = [
{ title:'One', url:'http://yahoo.com', bg:'#f8f8f8', width:'160', height:'600', imageAsset:'assets/imgs/web/MyWebsites_1.jpg', paragraph:'some text of some description'},
{ title:'Two', url:'http://google.com', bg:'#f8f8f8', width:'160', height:'600', imageAsset:'assets/imgs/web/MyWebsites_2.jpg', paragraph:'rabbit rabbit rabbit'},
{ title:'Three', url:'http://bambam.com', bg:'#f8f8f8', width:'160', height:'600', imageAsset:'assets/imgs/web/MyWebsites_3.jpg', paragraph:'blahiblahblah'}];
}
})
// GAME VIEWS ========================================
.state('game', {
url: '/game',
templateUrl: 'partial-game.html'
})
// CONTACT VIEWS ========================================
.state('contact', {
url: '/contact',
templateUrl: 'partial-contact.html'
})
});
【问题讨论】:
标签: linux angularjs node.js angular-ui-router