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

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

问题描述

我试图写一个AngularJS客户端唯一的应用程序。结果
我想我或许可以通过在地址栏中键入从Chrome中加载它:
文件:/// C:/path/to/project//index.html
我也试图调用铬旗--allow-文件访问 - 从 - 文件

不幸的是什么都没有发生 - 只是在标签名称是工作繁忙的标志结果。
为什么没有加载我的应用程序?

我用下面的code:

index.html的:

 <!DOCTYPE HTML>
< HTML NG-应用=应用程序>
< HEAD>
    &LT;脚本类型=文/ JavaScript的SRC =// cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.min.js\"></script>
    &LT;脚本类型=文/ JavaScript的SRC =// cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-route.js\"></script>
    &所述; SCRIPT SRC =app.js&GT;&下; /脚本&GT;
    &LT;标题&GT;&LT; /标题&GT;
&LT; /头&GT;
&LT;车身风格=背景色:白色;&GT;
&LT; H1&GT;指数&LT; / H1&GT;
&LT;一个ID =链接的href =/登录&GT;转到登录&LT; / A&GT;
&LT; NG-视图&gt;&LT; / NG-视图&gt;
&LT; /身体GT;
&LT; / HTML&GT;

app.js:

  angular.module('应用',['ngRoute'])。
   配置(函数($ routeProvider){
        $ routeProvider。
            当('/',{控制器:HomeCtrl,templateUrl:app.html'})。
            当('/登录',{控制器:LoginCtrl,templateUrl:'login.html的,决心:功能(){}})。
            否则({redirectTo:'/'});
    });功能HomeCtrl($范围){
    $ scope.numbers = [1,2,3,4,5];
}功能LoginCtrl($范围){}

app.html:

 &LT; D​​IV NG控制器=HomeCtrl&GT;
    &LT; UL NG重复=用数字编号&GT;
        &LT;立GT; {{数}}&LT; /李&GT;
    &LT; / UL&GT;
&LT; / DIV&GT;

编辑:

2可能的解决方案:


  1. 关闭所有Chrome实例以及运行命令行:结果C:\\ Program Files文件(x86)的\\谷歌\\铬\\应用\\的chrome.exe--allow-文件访问从档案--allow -file访问

  2. 运行火狐不具有此限制(像@GeekBoy提到)


解决方案

据我所知,谷歌浏览器不允许的JavaScript被从文件系统中运行。但是,我做了一个快速谷歌搜索,发现这一点。可能是有用的
链接

在不利的一面,你可以使用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天全站免登陆