I am trying to get $viewContentLoaded to work, but no matter what I try, it just refuses to fire. Here is where I am currently.
Javascript (directive.js)
var app = angular.module('myapp', []);
app.controller('MainCtrl', function($scope, $timeout) {
$scope.$on('$viewContentLoaded', function () {
$timeout(function () {
var x = document.getElementById("iframe");
alert(x); //Never Fires.
}, 0);
});
});
The HTML
<!DOCTYPE html>
<html ng-app="myapp">
<head>
<meta charset="utf-8" />
<script data-require="angular.js@1.2.x" src="http://code.angularjs.org/1.2.7/angular.js" data-semver="1.2.7"></script>
<script src="script/directive.js"></script>
</head>
<body ng-controller="MainCtrl">
<iframe id="iframe"></iframe>
</body>
</html>
I have tried this multiple ways:
I have taken the $timeout stuff out. I've tried using it combined with routing. I've tried using $watch in place of $on. This was able to give me an alert, but not at the correct time. I've tried this in IE11 and Chrome, neither work There is nothing logged in the console.
This just flat out will not work. Where am I going wrong?