Angular - after first attempt, console throwing error: "is not a function"
<p>I am using <a href="https://github.com/brandly/angular-youtube-embed" rel="nofollow">angular-youtube-embed</a> package for displaying youtube videos in an ionic app. I have a page where I list all the articles and I have a page for each article. It is working fine when I am trying to play videos when I am on the articles listing page, and when I go to the article page as well, but when I go back to the articles listing page, I can't play the videos anymore and I get the error:  </p>

<blockquote>
  <p>TypeError: youtubePlayer.playVideo is not a function</p>
</blockquote>

<p>This is the controller for the articles listing pages:</p>

<pre><code>$scope.playVideo = function(youtubePlayer, index) {
    $scope.videoPlaying[index] = true;
    youtubePlayer.playVideo();
  };

  $scope.$on('$ionicParentView.afterLeave', function(event, data) {
      $scope.videoPlaying = false;
  });
</code></pre>

<p>Articles listing page html:</p>

<pre><code>&lt;div class="iframe" ng-show="article.external_media.length &gt; 0 &amp;&amp; article.external_media.url != ''"&gt;
            &lt;img ng-hide="videoPlaying[$index]" class="img" ng-src="http://i1.ytimg.com/vi/{{ article.external_media[0].video_id }}/maxresdefault.jpg"&gt;
            &lt;youtube-video ng-show="!videoPlaying[$index]" video-url="article.external_media[0].original_url" player="youtubePlayer" player-vars="playerVars" class="iframe-video"&gt;&lt;/youtube-video&gt;
            &lt;h1 ng-hide="videoPlaying[$index]"&gt;{{ article.title.split(' ', 7).join(' ') }}&lt;/h1&gt;
            &lt;div ng-hide="videoPlaying[$index]" class="iframe-overlay" ng-click="playVideo(youtubePlayer, $index)"&gt;&lt;/div&gt;
            &lt;img ng-hide="videoPlaying[$index]" ng-click="playVideo(youtubePlayer, $index)" class="play" src="icons/play.svg"/&gt;
            &lt;img ng-hide="videoPlaying[$index]" ng-click="playVideo(youtubePlayer, $index)" class="playButton" src="icons/playRectangle.svg"/&gt;
          &lt;/div&gt;
</code></pre>