AngularJS: tree model object using dynamic template of directive -


I want to visit tree model object

But each sub-tree has different structures and the child has to attach every 1 second.

I wrote:

HTML ::

  & lt; Div ng-app = "MyApp" & gt; & Lt; Div ng-controller = "MainCtrl" & gt; & Lt; Input type = "button" ng-click = "init ()" value = "init" /> {{Obj}} & lt; Hour / & gt; Obj :: & lt; Example obj = "obj" & gt; & Lt; / Example & gt; & Lt; Hour / & gt; Obj1 :: & lt; Example obj = "obj1" & gt; & Lt; / Example & gt; & Lt; Hour / & gt; Obj1.id :: {{obj1.id | Json}} & lt; / Div & gt; & Lt; / Div & gt;   

javascript ::

  var app = angular Module ('myApp', []); {OB: '='}, Controller: Function ($ Range, $ element, $ etters) {$ Scope: (for example, 'E'), Trancelet: correct, $ $ Watch ($ attrs.obj, function Value) {var templates = "& lt; ol>"; // dynamic template console.log ("obege ::"); f = value; console.log ($ radius. Obj); angular.forEach ($ Scope.obj, function (value, field) {if (connular.ISERRE (value)} {template + = '
  • ' + area; template + = '& lt; div ng- repeat = "sobj In the obj. '+ Field +' "& gt; 'Template + =' & lt; Example obj =" sobj "& gt; & lt; / example & gt; '; template + =' & lt; / div & Gt; '; template + + & lt; / li & gt;';} Other {templates L = li & gt; '+ area + "::" + value + "";}}); template + = "& lt; / ol>"; $ Element.replace ($ element.html (template));});}};}) app.controller ('MainCtrl', function ($ radius) {$ scope.obj = {ifdsfds: 5, fdafdx: Enfasephadez 1 ', subob: [[id: 1, val:' hi ']]} $ $ scope.obj1 = {ID: 5, FDAFAIDS:' envelope 1 '}; $ scope. IT = function) {$ Scope. Obj = {id: 1, title: 'nfsfststy61'}}; $ Scope.counter = 0; $ Scope.ajax = function () {var number = Math. (Math. Random (* * 100 *); $ Scope.obj1.id = Number; // if ($ sscope.counter ++ & lt; 10) {setTimeout (function () {$ scope.ajax (); $ scope. $ Apply ();}, 3000); //} console.log ($ scope.counter + "=" + number); }; $ Scope.ajax (); });

    Problems:

    1. Changing the model obj.id setTimeout per second () Work {{obj.id}} changed.
    2. I do not want to use the template field

    3. Div class = "post-text" itemprop = "text ">

      You should add a viewer to the link function instead of the controller function and replace $ attrs.watch with a simple clock

        : Work ($ radius, $ elements, $ attrs) {$ scope. $ Watch ($ attrs.obj, function) with {  

      -

        link: work ($ radius, $ elements, $ attrs) { $ Scope. $ Watch ('obj', function (value) {   

  • Comments

    Popular posts from this blog

    c - Mpirun hangs when mpi send and recieve is put in a loop -

    python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

    java - Unable to get JDBC connection in Spring application to MySQL -