2

I have a Controller which has something like this...

angular.module('kZoneApp').controller('DemandController', ['$http', '$scope', '$rootScope', 'dataFactory', '$window', '$routeParams','$sce', function ($http, $scope,$rootScope, dataFactory, $window, $routeParams,$sce) {
 $scope.channel = $routeParams.channel;

now within my page.html, I want to do the following....

<script>
 YoutubeVideoPlayer.openVideo('{{channel}}');
</script>

please note, I am using Routes, and page.html is loaded into my ng-view Via a Route.

<div id="myView" class="reveal-animation" ng-view></div>

I tried below code, but it returns undefined....

$().ready(function () {
 var channel = angular.element("#myView").scope().channel 
 YoutubeVideoPlayer.openVideo(channel);
})

How can I get the value of Channel within my Template View?

Update

below works...but I am sure there has to be a cleaner solution

 setTimeout(function () {
 alert(angular.element("#myView").scope().channel)
 }, 500);
asked Jun 9, 2015 at 7:15
10
  • 1
    try change it to var channel = angular.element(document.getElementById("myView")).scope().channel Commented Jun 9, 2015 at 7:18
  • You should do it the other way round, make YoutubeVideoPlayer a constant in Angular. anuglar.module('someModule').constant('YouTube', YoutubeVideoPlayer) then access in a directive. Commented Jun 9, 2015 at 7:18
  • same result. see my update Commented Jun 9, 2015 at 7:19
  • Callum, could you please write a quick example? Commented Jun 9, 2015 at 7:20
  • 1
    plnkr example Commented Jun 9, 2015 at 7:36

1 Answer 1

1

A workaround solution should be creating a variable before your Angular.module definition.

var scopeInAngular = null;

and inside controller assign controller to your variable.

scopeInAngular = $scope;

then if you manipulate anything inside angular view use

scopeInAngular.$apply();
answered Jun 9, 2015 at 7:42

1 Comment

This worked. But still had to be placed within the setTimeout command.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.