AngularJS 编写一个没有服务器的应用程序 [英] AngularJS writing an app with no server

查看:30
本文介绍了AngularJS 编写一个没有服务器的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个仅限 AngularJS 客户端的应用程序.
我想我可以通过在地址栏中输入来从 chrome 加载它:file:///C:/path/to/project//index.html我还尝试使用标志 --allow-file-access-from-files

调用 chrome

不幸的是什么都没发生 - 只是标签名称上的忙碌标志有效.
为什么没有加载我的应用?

我正在使用以下代码:

index.html:

<html ng-app="app"><头><script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.min.js"></script><script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-route.js"></script><script src="app.js"></script><title></title><body style="background-color: white;"><h1>索引</h1><a id="link" href="/login">进入登录</a><ng-view></ng-view></html>

app.js:

angular.module('app', ['ngRoute']).配置(功能($routeProvider){$routeProvider.当('/',{控制器:HomeCtrl,templateUrl:'app.html'}).when('/login', {controller: LoginCtrl, templateUrl: 'login.html', resolve: function() {}}).否则({重定向到:'/'});});函数 HomeCtrl($scope) {$scope.numbers = [1,2,3,4,5];}函数 LoginCtrl($scope) {}

app.html:

<ul ng-repeat="数字中的数字" ><li>{{number}}</li>

2 种可能的解决方案:

  1. 关闭所有 chrome 实例并从命令行运行:
    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files --allow-文件访问
  2. 运行没有此限制的 Firefox(如@GeekBoy 提到的)

解决方案

据我所知 google chrome 不允许从文件系统运行 javascripts.但我做了一个快速的谷歌搜索并找到了这个.可能有用链接

另一方面,您可以使用 Firefox.据我所知,Firefox 没有这样的限制

I'm trying to write an AngularJS client side only app.
I thought I might be able to load it from chrome by typing in the address bar: file:///C:/path/to/project//index.html I also tried to invoke chrome with the flag --allow-file-access-from-files

Unfortunatly nothing happened - just the busy sign on the tab name is working.
Why does is not loading my app?

I'm using the following code:

index.html:

<!doctype html>
<html ng-app="app">
<head>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-route.js"></script>
    <script src="app.js"></script>
    <title></title>
</head>
<body style="background-color: white;">
<h1>Index</h1>
<a id="link" href="/login">Go to login</a>
<ng-view></ng-view>
</body>
</html>

app.js:

angular.module('app', ['ngRoute']).
   config(function($routeProvider) {
        $routeProvider.
            when('/', {controller: HomeCtrl, templateUrl: 'app.html'}).
            when('/login', {controller: LoginCtrl, templateUrl: 'login.html', resolve: function() {}}).
            otherwise({redirectTo:'/'});
    });

function HomeCtrl($scope) {
    $scope.numbers = [1,2,3,4,5];
}

function LoginCtrl($scope) {

}

app.html:

<div ng-controller="HomeCtrl">
    <ul ng-repeat="number in numbers" >
        <li>{{number}}</li>
    </ul>
</div>

Edit:

2 possible solutions:

  1. Close all chrome instances and run from command line:
    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files --allow-file-access
  2. Run Firefox which does not have this restriction (Like @GeekBoy mentioned)

解决方案

As far as I know google chrome does not allow javascripts to be run from file system. But I did a quick google search and found this. Might be useful Link

On the flipside you can use firefox. Firefox doesn't have such restrictions as far as I know

这篇关于AngularJS 编写一个没有服务器的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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