angularjs - Angular directive not working with ng-repeat -


I made an angular instruction but it will not work with ng-repeat I do not know why The second instruction runs successfully.

Javascript:

  Angular Module ('myApp', []). Controller ('Ctrl', ['$ scope', function ($ scope) {$ scope.vvv = []; $ scope.bbb = []; $ scope.testdatas = [{text: 0}, {text: 1 }, {Text: 2}, {text: 3}]}]]). Directive ('wstCheckbox', function) {return {restricted: 'EA, replace: correct, template:' & lt; Div ng-transclude & gt; & Lt; / Div & gt; , Scope: {modelname: '=' // ths is model}, translact: true, link: function (scope, element, etters) {console.log (element) $ (element). Find ('input' [type = ('input' (check) '). (' Change ', function () {scope.modelname = []; scope. $ Apply (function () {$ (element). ('Input [type = checkbox]: checked'). (Function () (scope.modelname.push ($ (this) .val ());}}}}}}}}})  < / Pre> 

HTML:

  
& lt; wst-checkbox model name = "VVV" & gt; & lt; div & Gt; {{vvv}} & lt; / div & gt; Input type = "checkbox" name = "test" value = "data.text" ng-repeat = "data in test data" /> gt; ; & Lt; / WST-checkbox & gt; & lt; wst-checkbox ModelName = "BBB">
{{bbb}} gt; Labels = "4"> index 0 Lt; input type = "checkbox" name = "test" value = "1" id = "5" /> gt; and label = "5"> index 1 gt; & lt; input Type = "checkbox" name = "test" value = "2" id = "6" />
label = "6"> Index 2 & lt; / Label & gt; & Lt; Input type = "checkbox" name = "test" value = "3" id = "7" /> gt; & Lt; / WST-checkbox & gt; & Lt; / Div & gt;

The problem is that at the point you are bound to change the event, angular is ng - Douba has not been provided so far if you want to give it time to render it to everyone, then it should be done.

Here is a job

  link: function (scope, element, etter) {console log (element) $ timeout (function () {$ (element) .find ('Input [type = checkbox]'). ('Change', function () {scope.modelname = []] scope. $ Apply function () {$ (element) .find ('input [type = Checkbox]: checked '). Each (function () {scope.modelname.push ($ (this) .val ());})})}})}, 0); }   

I will suggest you to use ng-change and ng-model in your input and will do more in a slightly more parallel way. You should know about the place that you are expected to use in mutually-used instructions.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -