javascript - Load angularjs controller dynamically from html -


i have 2 controllers. composite js object has elements+js objects+numerous arrays first controller

i want initialize 2nd controller multiple times various array objects respectively.

i using code iniatialize 2nd controller.

app.controller('sscontroller', function($scope) { $scope.init = function(initdata) {     $scope.initdata = initdata;      };  <div ng-controller="ttcontroller">     <div ng-controller="sscontroller" ng-init='init({currdata})'>     </div> </div> 

where currdata property of scope object of ttcontroller.

if pass hardcoded number in init, gets passed, not currdata object. integer value comes currdata, such currdata.id not getting passed.

any ideas how done ?

i think should writing directive , not controller. please consider following pattern.

<div ng-controller="ttcontroller">     <div my-process-array="datatowatch">     </div> </div> 

then

app.directive('myprocessarray', function(){     return function(scope, elem, attrs){          elem.bind('click', function(){              // click stuff           });           scope.$watch(attrs.myprocessarray, function(newdata, olddata){                // stuff data parent controller.           });     };        }); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -