如何当src网址是角范围内加载脚本? [英] How to load script when src url is in angular scope?

查看:127
本文介绍了如何当src网址是角范围内加载脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一些自定义的脚本加载存储在依赖于在客户端的一些逻辑,我有数据库。我的问题是如何去上班。

我的控制器:

 使用严格的;
angular.module('youshareApp')
    .controller('ShareCtrl',['$范围,$ routeParams','Projectservice',函数($范围,$ routeParams,Projectservice){
 $ scope.projectId = $ routeParams.projectId;
 $ scope.model.url =/ API / V1 /项目/ code /+ $ scope.projectId;
...}]);

我的观点:

 < D​​IV CLASS =容器NG-控制器=ShareCtrl的风格=的margin-top:50px​​的; >
< H3>目前您正在促进:LT; / H3 GT&;< D​​IV CLASS =行的风格=的margin-top:10px的;>
    < D​​IV CLASS =COL-MD-6><标签类=引领> {{model.name}}< /标签>< / DIV>
< / DIV>< D​​IV CLASS =行的风格=的margin-top:10px的;>
    < D​​IV CLASS =COL-MD-6>< p =班领导> {{model.description}}< / P>< / DIV>
< / DIV>
<脚本NG-SRC = {{model.url}} />
< / DIV>

我如何才能让这项工作?

我也试过这个<一个href=\"http://stackoverflow.com/questions/19028792/loading-an-external-script-using-script-src-in-angular\">post

通过这个模板:

 &LT; D​​IV HTML绑定不安全='HTML'&GT;&LT; / DIV&GT;

这在控制器:

  $ scope.html ='&LT;脚本的src =+ $ scope.model.url +'/&GT;';


解决方案

您必须声明的网址是安全的。你可以通过阅读一下就在这里:
https://docs.angularjs.org/error/ $ SCE / insecurl

这可能会发生的另一件事是,你不使用NG-SRC。

I'm trying to get some custom script to load that is stored in the database depending on some logic i have on client side. My problem is how to get to work.

My controller:

'use strict';
angular.module('youshareApp')
    .controller('ShareCtrl',['$scope','$routeParams' ,'Projectservice',function     ($scope,$routeParams,Projectservice) {
 $scope.projectId=$routeParams.projectId;
 $scope.model.url="/api/v1/project/code/"+$scope.projectId;
...

}]);

My view:

<div class="container" ng-controller="ShareCtrl" style="margin-top: 50px;" >
<h3>You are currently contributing to : </h3>

<div class="row" style="margin-top: 10px;">
    <div class="col-md-6"><label class="lead">{{model.name}}</label></div>
</div>

<div class="row" style="margin-top: 10px;">
    <div class="col-md-6"><p class="lead" >{{model.description}}</p></div>
</div>
<script ng-src={{model.url}} />
</div>

How could i make this work?

I also tried this post

With this in the template:

    <div html-bind-unsafe='html'></div>

And this in the Controller:

    $scope.html='<script src="'+$scope.model.url+'" />';

解决方案

You must declare the url to be safe. You can do that by reading a bit on it here : https://docs.angularjs.org/error/$sce/insecurl

another thing that could be happening is that you are not using ng-src.

这篇关于如何当src网址是角范围内加载脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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