Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

javascript - Angular js scope var value in iframe

I am working with angular js . I have a controller "youTubePlayerCtrl", in this controller i have $scope.videoID which contains the youtube video id. I am able to get this value in belows div in h1 block . but i am not able to get {{videoID}} in iframe, can any one help me how to fix this.

<div ng-controller="youTubePlayerCtrl">
    <h1>{{videoID}}</h1>
    <iframe class="youtube-player" type="text/html" width="auto"
        height="auto" src="http://www.youtube.com/embed/{{videoID}}"
        allowfullscreen frameborder="0"> </iframe>
</div>

This is the error log:

[$interpolate:noconcat] http://errors.angularjs.org/undefined/$interpolate/noconcat?p0=http%3A%2F%2Fwww.youtube.com%2Fembed%2F%7B%7BvideoID%7D%7D at Error () at http://code.angularjs.org/1.2.0-rc.2/angular.min.js:6:453 at g (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:69:467) at b.push.compile (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:54:6) at l (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:47:124) at f (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:41:361) at l (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:47:64) at f (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:41:361) at http://code.angularjs.org/1.2.0-rc.2/angular.min.js:40:434 at http://code.angularjs.org/1.2.0-rc.2/angular-route.min.js:7:148 angular.js:7861 (anonymous function)

Jsfiddle (not working)

Thanx

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First: you need to use ng-src instead of src as @Cherniv suggested in a comment to your question. Read more here.

Second: you cannot concatenate the URL inside the source attribute for security reasons: you must concatenate the URL in Javascript in a scope variable e.g. fullURL and then ng-src="{{fullURL}}". Read more here.

Third: if Strict Contextual Escaping (SCE) is enabled ? and Angular v1.2 ships with SCE enabled by default ? you need to whitelist the URLs. Read more here and here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...