Despite being equal to online examples, I can not just wrap my head around properly
Use ng-model for my custom instructions.
I wanted to implement a custom command that would definitely be a & lt; Select & gt; tag that, when selected, the boolean is set in the model.
In short, I want to be able to use my instructions:
& lt; My-directve ng-model = "amodel.options" & gt; & Lt; / My-directions & gt; This is a must to choose when the user chooses to set an option update amodel.options accordingly:
- Option A:
amodel.options.foo = true,amodel.options.bar = false - Option B:
amodel.options. Foo = false,amodel.options.bar = true - Option C:
amodel.options.foo = true,Amodel .options.bar = true
How do I complete this? I've got this far away:
Angular Module ("myApp"). Directive: "ngmodel", option: {}, template: Select '& lt; ng-model =' ("my directive"), function () {return: restricted: "e", replace: true: Optional ">" + '& lt; Option Value = "0" & gt; Option A & lt; / option & gt;' + '& lt; Option Value = "1" & gt; Option B & lt; Option / {Watch} {$ foo: true, bar: false}, {foo: false, bar: true}, {foo: true, bar: true}] scope. $ Watch ("internal", function Val) {NgModel. ModelValue.foo = Mapping [Val] .f Land; Anjimodel. Model $ valueValue.bar = mapping [Val] Kbar;});};};}); But all this gives me an error that the NG-model is used arbitrarily.
I tried to go with different tutorials but none of them worked for me.
How do I do this correctly?
Thanks in advance!
The problem is that you change the to attribute to true Setting it to means two things:
- The director's HTML will be replaced by
templateHTML - ; The old element will have all the properties / squares
This is the last step, due to which the "ng-model Is used redundantly " error
To fix this, you only need to delete the replace attribute. Also, please keep in mind that the will be attribute, so the sooner You will stop using it, the better.
Comments
Post a Comment