-1

I want to see that 2 contorller called by 1 contorller. How to make it call? PS. B is in the iframe tag. Please help me.

now html source structure

A.html (A.js) 
B.html (B.js) A children tag -  iframe

now js source (A.js)

var app = angular.module('upload',[nUpload]); //nUpload is other module 
app.controller('upload',[$scope,nupload,
function($scope,nupload){           //nupload is service of nUpload module 
            .... //fileupload 
}]);                         ----- **1contorller**   

B.js (js file is in the other html tag (iframe))

var app = angular.module('progress',['']);</br>
app.controller('progress',[$scope,,,,] function($scope,,){
          ... //draw progress } 
);                   ----- **2contorller**   

I dream of sources (A.js)

app.controller('upload',,,,
function(,,,){
    B.progress = "10%"
}
dingo_d
  • 11,160
  • 11
  • 73
  • 132
inyoung
  • 1
  • 1

1 Answers1

0

Mmm.. to share objects between controllers you need an factory.

Try this:

A.js

var app = angular.module('upload',[nUpload,'container']);

app.controller('upload',[$scope,nupload,'Progress',
function($scope,nupload,Progress){
    Progress.setProgress("10%");
}]);

B.js

var app = angular.module('progress',['container']);

app.controller('progress',[$scope,'Progress',,, function($scope,Progress){
  var progressData = Progress.getProgress();

 }]); 

container.js

var app = angular.module('container',[]);

app.factory("Progress",[function(){
   var progress = "0%";
   return {
     getProgress: function() {
        return progress;
     }
     setProgress: function(data) {
        progress = data;
     }
   }
}]);

Hope this help you.

;D

Javierif
  • 632
  • 1
  • 6
  • 18
  • Thank you so much! @Javierif :) – inyoung Nov 24 '15 at 23:46
  • if function called by A.js (Progress.setProgress) – inyoung Nov 25 '15 at 02:48
  • when function called by A.js (Progress.setProgress),can i update or binding various of B.js ?.. i still don't know angular js framework....:( help me angle!! – inyoung Nov 25 '15 at 02:55
  • just like this source{setProgress: function(data) { progress = data; var ifr = parent.document.getElementById('iframeId'); var doc = ifr.contentWindow || ifr.contentDocument; if ( doc.document ) doc =doc.document; var scope = angular.element( doc.getElementById('ProgressId') ).scope(); scope.$apply(function() { scope.upload(); }); }} – inyoung Nov 25 '15 at 09:06
  • mmm... u can use $watch to this.. wait i paste a snipet code – Javierif Nov 25 '15 at 09:23
  • mmm... u can do this: http://stackoverflow.com/questions/12576798/angularjs-how-to-watch-service-variables If u need more information how to build this, create a new question in a comment I do not have enough space to write it :P (And comment here with url) – Javierif Nov 25 '15 at 09:36