Angular JS 动态 ng-src 在 1.2.0-rc.2 中不起作用 [英] Angular JS dynamic ng-src not working in 1.2.0-rc.2

查看:23
本文介绍了Angular JS 动态 ng-src 在 1.2.0-rc.2 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Angular JS 应用程序中实现一个视频元素,而 ng-src 不会读取范围变量

I'm trying to implement a video element in an angular JS app and the ng-src won't read the scope variable

我使用的是 1.2.0-rc.2

I'm using 1.2.0-rc.2

<!DOCTYPE html>
<html ng-app="ngView">

<head>
   <script src="http://code.angularjs.org/1.2.0-rc.2/angular.min.js"></script>

   <script>
   var app = angular.module('ngView', []);
   function MyControl($scope){
      $scope.file = '1234.mp4';
   }
  </script>
  </head>
  <body ng-controller="MyControl">
      <video controls  ng-src="http://www.thebigdot.com/{{file}}"></video>
  </body>
</html>

如果我使用旧版本的 AngularJS 库,它可以工作.

If I use a much older version AngularJS lib, it works.

cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js (works)

这是最新版本中的错误还是故意禁用的?有什么解决办法?

Is this a bug in the latest release or has it been disabled on purpose? What is the work around ?

推荐答案

经过一番调试我发现错误是这样的:

after a bit of debugging I found that the error is this:

<代码>错误:[$interpolate:noconcat] 插值时出错:http://www.thebigdot.com/{{file}}严格上下文转义不允许在需要可信值时连接多个表达式的插值.参见 http://docs.angularjs.org/api/ng.$sce

Error: [$interpolate:noconcat] Error while interpolating: http://www.thebigdot.com/{{file}} Strict Contextual Escaping disallows interpolations that concatenate multiple expressions when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce

http://errors.angularjs.org/1.2.0-rc.2/$interpolate/noconcat?p0=http%3A%2F%2Fwww.thebigdot.com%2F%7B%7Bfile%7D%7D在 http://code.angularjs.org/1.2.0-rc.2/angular.js:78:12在 $interpolate (http://code.angularjs.org/1.2.0-rc.2/angular.js:6953:17)attrInterpolateLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:5367:27)在 nodeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:5121:13)在复合链接Fn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4640:15)在 nodeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:5115:24)在复合链接Fn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4640:15)在复合链接Fn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4643:13)在 publicLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4549:30)在 http://code.angularjs.org/1.2.0-rc.2/angular.js:1157:27 angular.js:7861

http://errors.angularjs.org/1.2.0-rc.2/$interpolate/noconcat?p0=http%3A%2F%2Fwww.thebigdot.com%2F%7B%7Bfile%7D%7D at http://code.angularjs.org/1.2.0-rc.2/angular.js:78:12 at $interpolate (http://code.angularjs.org/1.2.0-rc.2/angular.js:6953:17) at attrInterpolateLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:5367:27) at nodeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:5121:13) at compositeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4640:15) at nodeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:5115:24) at compositeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4640:15) at compositeLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4643:13) at publicLinkFn (http://code.angularjs.org/1.2.0-rc.2/angular.js:4549:30) at http://code.angularjs.org/1.2.0-rc.2/angular.js:1157:27 angular.js:7861

这篇文章解释了正在发生的事情以及如何禁用严格上下文转义:http://docs.angularjs.org/api/ng.$sce

this article explains what is going on and how to disable the Strict Contextual Escaping: http://docs.angularjs.org/api/ng.$sce

这篇关于Angular JS 动态 ng-src 在 1.2.0-rc.2 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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