GVKun编程网logo

在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?(angular ng指令)

9

如果您想了解在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?和angularng指令的知识,那么本篇文章将是您的不二之选。我们将深入剖析在使用AngularJS

如果您想了解在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?angular ng指令的知识,那么本篇文章将是您的不二之选。我们将深入剖析在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?的各个方面,并为您解答angular ng指令的疑在这篇文章中,我们将为您介绍在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?的相关知识,同时也会详细的解释angular ng指令的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?(angular ng指令)

在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?(angular ng指令)

我正在使用AngularJS编写Chrome应用程序.我知道在访问外部图像时,您必须执行跨源 XMLHttpRequest并将它们作为blob提供.

我有一堆内部图像(本地应用程序资源),它们遵循我想在ngRepeat中显示的模式.

我可以通过以下方式静态加载图像:

<img src="images/image1.png"/>

但是,当我尝试在这样的重复中使用它们时:

<div ng-repeat="item in myList">
    <img ng-src="{{item.imageUrl}}"/>
</div>

我得到每个图像的错误(尽管错误中的图像确实存在),如下所示:

Refused to load the image 'unsafe:chrome-extension://hcdb...flhk/images/image1.png' because it violates the following Content Security Policy directive: "img-src 'self' data: chrome-extension-resource:".

我已经能够使用ng-src和XHR成功加载外部资源.对于动态加载的内部资源,是否必须遵循相同的模式?

更新 – 另一个简单示例

从最简单的Chrome应用程序(https://github.com/GoogleChrome/chrome-app-samples/tree/master/hello-world)开始,以下内容将在Chrome应用程序之外(在浏览器中)运行,但不在Chrome应用程序中:

的index.html

<!DOCTYPE html>
<html ng-app ng-csp>
<head>
    <title>Hello World</title>
    <script src="js/angular.min.js"></script>
    <script src="js/test.js"></script>
</head>
<body ng-controller="Ctrl">
    <img ng-src="{{imageUrl}}"/>
</body>
</html>

test.js

function Ctrl($scope) {
    $scope.imageUrl = 'hello_world.png';
}
我刚刚在另一个堆栈溢出问题中找到答案:

Angular changes urls to “unsafe:” in extension page

Angular有一个白名单正则表达式,图像src url必须匹配才能更改src. chrome-extension:// url默认情况下不匹配,因此您必须更改它.浏览此处获取更多信息:

http://docs.angularjs.org/api/ng/provider/ $compileProvider

我添加了以下代码以允许chrome-extension // urls到白名单(使用其他stackoverflow问题答案中的代码):

angular.module('myApp',[])
.config( [
    '$compileProvider',function( $compileProvider ) {
        var currentImgSrcSanitizationWhitelist = $compileProvider.imgSrcSanitizationWhitelist();
        var newImgSrcSanitizationWhiteList = currentImgSrcSanitizationWhitelist.toString().slice(0,-1)
        + '|chrome-extension:'
        +currentImgSrcSanitizationWhitelist.toString().slice(-1);

        console.log("Changing imgSrcSanitizationWhiteList from "+currentImgSrcSanitizationWhitelist+" to "+newImgSrcSanitizationWhiteList);
        $compileProvider.imgSrcSanitizationWhitelist(newImgSrcSanitizationWhiteList);
    }
]);

angularjs – Angular $digest循环使Chrome 50眨眼

angularjs – Angular $digest循环使Chrome 50眨眼

This question显示了一个问题,当< select>的选项列表绑定到$scope的某个值时,$scope的摘要事件将导致打开的< select>闪烁.

但是,我发现闪烁效果只发生在OS X上的Chrome 50上,即如果在OS X中的Firefox或Windows上的Chrome上打开列表时发生$摘要,我将看不到闪烁.

这会是Chrome的错误吗?如何防止这种影响?因为如果没有更改选项的元素,人们不希望看到< select>元素眨眼.

我正在研究一个可以用最少的代码在线看到效果的例子.我当前项目的一个例子如下.

<selectng-model="application.choiceOfTeams[0]" ng-options="team.name for team in teams">
    <option value="">-- select team --</option>
</select>
<selectng-model="application.choiceOfJobs[0]"
            ng-show="application.choiceOfTeams[0].jobs"
            ng-options="job.name for job in application.choiceOfTeams[0].jobs">
    <option value="">-- select position from {$application.choiceOfTeams[0].name $} --</option>
</select>
这听起来像你链接的帖子一样的问题.

它似乎是这个错误:

https://bugs.chromium.org/p/chromium/issues/detail?id=613885

正如评论中所建议的,在select上设置转换为none已经解决了这个问题,在我的情况下(使用bootstrap)使用以下方法:

select.form-control { transition: none; }

要在没有引导程序的情况下使用,或者在不使用.form-control类的情况下使用,只需删除.form-control选择器并确保其他任何内容都不会覆盖select元素的transition属性:

select { transition: none; }

angularjs – Angular Js路由谷歌Chrome问题

angularjs – Angular Js路由谷歌Chrome问题

使用下面提到的Code1在角度Js中进行基本路由并获得“ XMLHttpRequest无法加载交叉源请求仅支持协议方案:http,数据,chrome扩展,https,chrome-extension-resource”错误并且我们必须使用本地Web服务器解析相同的和下载的MAMP并保持我的html [login.html]在htdocs文件夹中启动服务器并用Code2中提到的[localhostURL / AngularJs / login.html’]替换templateUrl并获得错误错误:[ $sce:insecurl]下面给出了确切的错误,指导我在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!

码2

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

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

错误代码1: –
XMLHttpRequest无法加载file:// localhost / Users / karthicklove / Documents / Aptana Studio 3 Workspace / Object_Javascript / Angular_Js / Routing / login.html.交叉源请求仅支持协议方案:http,chrome-extension-resource.

错误代码2: – [$sce:insecurl] http://errors.angularjs.org/1.2.26/ $sce / insecurl?p0 = http:// localhost:8888 / AngularJs / login.html出错(本机)

我得到了类似的错误.我得到了一个解决方案,我们不能在AngularJS中使用Routing将它保存在你的文件系统中. (即)file:/// C:/Users/path/to/file.html?r = 4383065’如果您使用此URL运行,您将收到错误.路由提供程序将使用http协议.因此,您必须将代码放在localhost中,然后从浏览器localhost / foldername / index.html运行.不要直接从文件夹中运行它

并且还像这样更改模板URL

templateUrl: '/AngularJs/login.html'

如果你有疑问在这里发布.

angularjs – Angular – 我可以从角度应用程序外部广播消息吗?

angularjs – Angular – 我可以从角度应用程序外部广播消息吗?

我有一个场景,我需要非角度代码(在这种情况下Facebook和Twitter JS sdk)来广播角度控制器可以收听的事件.为什么?在初始页面加载后,我通过 AJAX加载和修改页面中的内容.内容有多个喜欢/推特按钮(如博客/聚合器的首页).我想在Facebook“喜欢”按钮或Twitter“分享”按钮上发生点击时添加事件挂钩 – 页面中有一些,每当获取新内容时每个都在变化(再次,通过ajax ).

现在,SDK的处理方式不同:

推特

twttr.events.bind('click',function(event){
    // here I'd like to somehow
    // $rootScope.$broadcast("twitter:clicked",event.currentTarget)
});

Facebook的

FB.Event.subscribe("edge.create",function(resp) {
    // here I'd like to somehow
    // $rootScope.$broadcast("facebook:clicked",resp)
});

一些控制器

app.controller("SomeController",['$scope',function($scope) {
    $scope.$on("facebook:clicked",function(event,resp) {
        // do something with resp
    });

    $scope.$on("twitter:clicked",target) {
        // do something target
    });
}])

我们的想法是绑定这些事件处理程序,然后处理相关控制器中的广播消息,即使每次获取新内容时都会重新创建这些控制器.

所以基本上,我正在寻找的是一种方法来挂钩现有的已经初始化的角度应用程序的$rootScope和$广播消息,尽管不是应用程序的一部分.希望这是有道理的.谢谢.

解决方法

您可以绑定到Angular代码中的其他应用程序(在最有可能创建链接的指令中).这样您就可以访问$rootScope.

或者,如果您手动引导应用程序,则可以保留对注入器的引用并获取$rootScope:

var injector = angular.bootstrap(element,["myAppModule",...]);
var $rootScope = injector.get("$rootScope");

在任何情况下都不要忘记在外部事件后调用$apply.

angularjs – angular.js chrome Access-Control-Allow-Origin

angularjs – angular.js chrome Access-Control-Allow-Origin

我正在尝试使用Angular.js服务从Jersey / Spring的REST服务中获取 JSON.

当我使用Firefox时,它工作正常,但当我去Chrome时我收到了消息:

XMLHttpRequest cannot load http://localhost:8080/VirtualLawyerPj/services/timeoftheday/asjson/tue. Origin http://localhost:8090 is not allowed by Access-Control-Allow-Origin.

这是我的服务代码:

angular.module('myAppServices',['ngResource']).
factory('Time',function($resource){
    return $resource('http://localhost:port/VirtualLawyerPj/services/timeoftheday/asjson/tue',{port:":8080"},{
        query: {method:'GET',params:{},isArray:false}
    });
});

有人有同样的问题吗?
你是怎么做到这一点的?

谢谢.

CORS解决方案在 html5rocks教程中描述.为我工作.

今天关于在使用AngularJS的Chrome应用中,我可以直接将ngSrc指令用于内部图像吗?angular ng指令的讲解已经结束,谢谢您的阅读,如果想了解更多关于angularjs – Angular $digest循环使Chrome 50眨眼、angularjs – Angular Js路由谷歌Chrome问题、angularjs – Angular – 我可以从角度应用程序外部广播消息吗?、angularjs – angular.js chrome Access-Control-Allow-Origin的相关知识,请在本站搜索。

本文标签: