Angular Js路由Google Chrome问题 [英] Angular Js Routing Google Chrome Issue

查看:336
本文介绍了Angular Js路由Google Chrome问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面提到的Code1处理角型J中的基本路由,并获得 XMLHttpRequest无法加载协议方案仅支持跨域源请求:http,data,chrome-extension,https,chrome-extension-resource <强>>错误,并建立,我们必须使用本地Web服务器解决相同和下载的MAMP,并保持我的html [login.html]在htdocs文件夹启动服务器,并替换templateUrl与[localhostURL / AngularJs / login.html']作为在Code2中提到并收到错误:[$ sce:insecurl] 确切错误的错误,请指导我使用任何解决方案在Google Chrome中修复此错误...

Worked on basic routing in angular Js with Code1 mentioned below and getting "XMLHttpRequest cannot load Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource" error and founded that we must use local web server to resolve the same and downloaded MAMP and kept my html[login.html] in htdocs folder started the server and replaced templateUrl with [localhostURL/AngularJs/login.html'] as mentioned in Code2 and getting error of Error: [$sce:insecurl] exact error are given below, Guide me with any solution to fix the same in Google Chrome...

代码1

index.html

<!DOCTYPE html>
 <html>
    <head>
    <title>Test</title>
    </head>
    <body ng-app="plunker">
    <div ng-view=""></div>    
    <script src="angular.min.js"></script>
    <script src="angular-route.js"></script>
    <script src="app.js"></script>  
   </body>
 </html>

app.js

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

login.html

   Hello from login! 

Code2

所有其他事情与只在app.js中的更改相同

All other thing are same with changes only in app.js

   var app = angular.module('plunker', ['ngRoute']);
   app.config(function ($routeProvider) {
   $routeProvider.when('/login',{
        controller: '',
        templateUrl: 'http://localhost:8888/AngularJs/login.html'
    }).otherwise({ 
        redirectTo: '/login' 
    });
});

错误代码1 : -
XMLHttpRequest无法加载文件://localhost/Users/karthicklove/Documents/Aptana%20Studio%203%20Workspace/Object_Javascript/Angular_Js/Routing/login.html。跨原始请求仅支持协议方案:http,数据,chrome扩展,https,chrome扩展资源。

错误代码2 : - [$ sce:insecurl] http://errors.angularjs.org /1.2.26/ $ sce / insecurl?p0 = http%3A%2F%2Flocalhost%3A8888%2FAngularJs%2Flogin.html at Error(native)

Error Code2:- [$sce:insecurl] http://errors.angularjs.org/1.2.26/$sce/insecurl?p0=http%3A%2F%2Flocalhost%3A8888%2FAngularJs%2Flogin.html at Error (native)

推荐答案

我得到了类似的错误。我有一个解决方案,我们不能使用路由在AngularJS通过保持在您的文件系统。 (ie)file:/// C:/Users/path/to/file.html?r = 4383065'如果你运行这个URL,你会得到错误。路由提供程序将使用http协议。所以你必须把你的代码放在localhost里,然后从浏览器localhost / foldername / index.html运行。 不要直接从文件夹中运行

I got the similar error. I got a solutions for this, we cannot use Routing in AngularJS by keeping it in your file system. (i.e)file:///C:/Users/path/to/file.html?r=4383065' If you run with this URL you will get error. The route provider will use http protocol. So you have to put your code inside the localhost and then run from browser localhost/foldername/index.html . Don't run it from the folder directly

同时更改您的模板网址

     templateUrl: '/AngularJs/login.html'

如果您有任何疑问,请点击这里。

If you have doubt post here.

这篇关于Angular Js路由Google Chrome问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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