I am working on a side project where I have to open a 3rd party service in an iframe. And I have list of alternative 3rd party substitute service. So, lets say if the first third party service takes too much time(>10s), then I will make request to substitute third party services using setTimeout and setTimeInterval and promises.
For that I have created a html file which will be loaded by default on the iframe, and after that all the functionality of redirection and timer are written in controller of the same html file. So that timer service can be started and if the third party website loads on the iframe, it will wash the html file, so the controller code.
But the problem here is my html file is not loading on the controller.
(Note: Assume as if I am novice in JS and angularJS).
File – redirection.html
<div>
<div class="loader">
Hello World
</div>
</div>
Code from which frame is loading:
<div class="col h-100" ng-show="requestVersion==2">
<iframe id="iFrame" class="col-12 h-100 no-border text-center" src="{{redirectionUrl}}">
</iframe>
</div>
Controller code for the redirection.html:
const angular = require("angular");
function redirectionCtrl($scope, $state, $timeout, $window, ENV, parentDoc, httpSrvc, miscSrvc, windowMessagingService) {
"ngInject";
let model = {
//some code
}
function fetchMessage() {
// some code
}
function fetchData(){
// some code
}
function updateDataAndRedirect(){
// some code
}
function init() {
console.log("redirection init works!")
angular.extend($scope, model);
console.log(":Element loaded")
let copyElement = document.createElement("span");
copyElement.appendChild(document.createTextNode("Hello Wolrd"));
copyElement.id = 'tempCopyToClipboard';
angular.element(document.body.append(copyElement));
fetchMessage();
updateDataAndRedirect();
}
init();
}
module.exports={
name : "redirectionCtrl",
controller : redirectionCtrl
};
And setting up url is here:
.state('espRedirection', {
url: "/redirection",
templateUrl: 'templates/redirection.html',
resolve : {
controller: function ($q) {
return $q(function (resolve, reject) {
return require.ensure('./javascripts/controllers/redirectionCtrl',
function (require) {
let mod = require('./javascripts/controllers/redirectionCtrl');
$controllerProvider.register(mod.name, mod.controller);
resolve();
},
function (err) {
console.log(err);
reject(err);
},
"home"
);
});
}
},
views:{
"content@home" : {
templateUrl: 'templates/redirection.html',
controller : "redirectionCtrl",
},
"header@home" : {
templateUrl: 'templates/header.html',
controller : "defaultHeaderCtrl"
},
"sidebar@home" : {
templateUrl: 'templates/sidebar.html',
controller : "defaultSidebarCtrl"
}
}
})
And here is the output:
[enter image description here](https://i.stack.imgur.com/REM1t.png)