Map ng-model array values with the object of ng-options for selected optionsHow do I set the value property in AngularJS' ng-options?Why does AngularJS include an empty option in select?how to set the default 'select' ng-model to an object?issues with select field's empty optionselect ng-options issue in angular jsng-options selects element at index 0, when ng-model is null (only after digest loop)Updating array used by ng-options, refresh selected objectng-options default option object is not selecting with an array of objectsangularjs select option with valueAngularJS ng-model array

Print the phrase "And she said, 'But that's his.'" using only the alphabet

Can you cover a cube with copies of this shape?

Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?

How did space travel spread through the galaxy?

How can a flywheel makes engine runs smoothly?

Is the infant mortality rate among African-American babies in Youngstown, Ohio greater than that of babies in Iran?

How to search for Android apps without ads?

At what temperature should the earth be cooked to prevent human infection?

Is it possible for underground bunkers on different continents to be connected?

How do I run a script as sudo at boot time on Ubuntu 18.04 Server?

How to sort human readable size

Is my research statement supposed to lead to papers in top journals?

How do I gain the trust of other PCs?

How to ask if I can mow my neighbor's lawn

Why are almost all the people in this orchestra recording wearing headphones with one ear on and one ear off?

Why is an array with a single number in it considered a number?

How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?

...and then she held the gun

How do CMB photons 'gain energy when they pass through normal regions of space with matter' and 'lose energy when they pass through voids'?

Is this set open or closed (or both?)

Basic power tool set for Home repair and simple projects

How to prevent cables getting intertwined

Using roof rails to set up hammock

Will users know a CardView is clickable?



Map ng-model array values with the object of ng-options for selected options


How do I set the value property in AngularJS' ng-options?Why does AngularJS include an empty option in select?how to set the default 'select' ng-model to an object?issues with select field's empty optionselect ng-options issue in angular jsng-options selects element at index 0, when ng-model is null (only after digest loop)Updating array used by ng-options, refresh selected objectng-options default option object is not selecting with an array of objectsangularjs select option with valueAngularJS ng-model array






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have following values:



campaign_sms_templates = [11,22];


and



templateSMSList = [
"id":11, "name":"test",
"id":12, "name":"test 12",
"id":22, "name":"test 22"
];


And angular code is like:



<select multiple="multiple"
ng-model="campaign_sms_templates"
ng-options="value as value.name for value in templateSMSList track by value.id">
</select>


But values are not selected on rendering. When I change campaign_sms_templates parameter values with:



campaign_sms_templates = [ "id":11, "id":22 ];


It works as objects matches and on rendering it displays selected values.



Can anyone help, how I can render selected options by using these values:



campaign_sms_templates = [11,22];


Please do let me know if is there anything need more clarifications.










share|improve this question
























  • well select works that way, do you mind mapping your array to array of objects before you bind to view .

    – super cool
    Mar 25 at 4:40











  • thanks @supercool just resolved the problem after spending lots of hours in this :( please check and share your feedback .

    – Shadman
    Mar 25 at 6:29

















0















I have following values:



campaign_sms_templates = [11,22];


and



templateSMSList = [
"id":11, "name":"test",
"id":12, "name":"test 12",
"id":22, "name":"test 22"
];


And angular code is like:



<select multiple="multiple"
ng-model="campaign_sms_templates"
ng-options="value as value.name for value in templateSMSList track by value.id">
</select>


But values are not selected on rendering. When I change campaign_sms_templates parameter values with:



campaign_sms_templates = [ "id":11, "id":22 ];


It works as objects matches and on rendering it displays selected values.



Can anyone help, how I can render selected options by using these values:



campaign_sms_templates = [11,22];


Please do let me know if is there anything need more clarifications.










share|improve this question
























  • well select works that way, do you mind mapping your array to array of objects before you bind to view .

    – super cool
    Mar 25 at 4:40











  • thanks @supercool just resolved the problem after spending lots of hours in this :( please check and share your feedback .

    – Shadman
    Mar 25 at 6:29













0












0








0


1






I have following values:



campaign_sms_templates = [11,22];


and



templateSMSList = [
"id":11, "name":"test",
"id":12, "name":"test 12",
"id":22, "name":"test 22"
];


And angular code is like:



<select multiple="multiple"
ng-model="campaign_sms_templates"
ng-options="value as value.name for value in templateSMSList track by value.id">
</select>


But values are not selected on rendering. When I change campaign_sms_templates parameter values with:



campaign_sms_templates = [ "id":11, "id":22 ];


It works as objects matches and on rendering it displays selected values.



Can anyone help, how I can render selected options by using these values:



campaign_sms_templates = [11,22];


Please do let me know if is there anything need more clarifications.










share|improve this question
















I have following values:



campaign_sms_templates = [11,22];


and



templateSMSList = [
"id":11, "name":"test",
"id":12, "name":"test 12",
"id":22, "name":"test 22"
];


And angular code is like:



<select multiple="multiple"
ng-model="campaign_sms_templates"
ng-options="value as value.name for value in templateSMSList track by value.id">
</select>


But values are not selected on rendering. When I change campaign_sms_templates parameter values with:



campaign_sms_templates = [ "id":11, "id":22 ];


It works as objects matches and on rendering it displays selected values.



Can anyone help, how I can render selected options by using these values:



campaign_sms_templates = [11,22];


Please do let me know if is there anything need more clarifications.







angularjs components multi-select bootstrap-multiselect






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 6:35









wentjun

5,6331422




5,6331422










asked Mar 25 at 3:34









ShadmanShadman

4922817




4922817












  • well select works that way, do you mind mapping your array to array of objects before you bind to view .

    – super cool
    Mar 25 at 4:40











  • thanks @supercool just resolved the problem after spending lots of hours in this :( please check and share your feedback .

    – Shadman
    Mar 25 at 6:29

















  • well select works that way, do you mind mapping your array to array of objects before you bind to view .

    – super cool
    Mar 25 at 4:40











  • thanks @supercool just resolved the problem after spending lots of hours in this :( please check and share your feedback .

    – Shadman
    Mar 25 at 6:29
















well select works that way, do you mind mapping your array to array of objects before you bind to view .

– super cool
Mar 25 at 4:40





well select works that way, do you mind mapping your array to array of objects before you bind to view .

– super cool
Mar 25 at 4:40













thanks @supercool just resolved the problem after spending lots of hours in this :( please check and share your feedback .

– Shadman
Mar 25 at 6:29





thanks @supercool just resolved the problem after spending lots of hours in this :( please check and share your feedback .

– Shadman
Mar 25 at 6:29












2 Answers
2






active

oldest

votes


















0














After spending lots of time in this, now finally I have resolved this



<select multiple="multiple" ng-change="save(campaign_sms_templates)" ng-model="campaign_sms_templates">
<option value=[[field.id]] ng-repeat="field in templateSMSList" ng-selected="campaign_sms_templates.indexOf(field.id)!==-1">[[field.name]]</option>
</select>


It seems not a good practice but as I only want to save ids in my database documents so I did this.



Any feedback are welcome.






share|improve this answer






























    0














    Use value.id as value.name for value:



    <select multiple="multiple"
    ng-model="campaign_sms_templates"
    ng-options="value.id as value.name for value in templateSMSList">
    </select>


    Also leave out the track by expression as it is not needed and will break the directive.



    For more information, see




    • AngularJS ng-options Directive API Reference - select as and track by.





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330947%2fmap-ng-model-array-values-with-the-object-of-ng-options-for-selected-options%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      After spending lots of time in this, now finally I have resolved this



      <select multiple="multiple" ng-change="save(campaign_sms_templates)" ng-model="campaign_sms_templates">
      <option value=[[field.id]] ng-repeat="field in templateSMSList" ng-selected="campaign_sms_templates.indexOf(field.id)!==-1">[[field.name]]</option>
      </select>


      It seems not a good practice but as I only want to save ids in my database documents so I did this.



      Any feedback are welcome.






      share|improve this answer



























        0














        After spending lots of time in this, now finally I have resolved this



        <select multiple="multiple" ng-change="save(campaign_sms_templates)" ng-model="campaign_sms_templates">
        <option value=[[field.id]] ng-repeat="field in templateSMSList" ng-selected="campaign_sms_templates.indexOf(field.id)!==-1">[[field.name]]</option>
        </select>


        It seems not a good practice but as I only want to save ids in my database documents so I did this.



        Any feedback are welcome.






        share|improve this answer

























          0












          0








          0







          After spending lots of time in this, now finally I have resolved this



          <select multiple="multiple" ng-change="save(campaign_sms_templates)" ng-model="campaign_sms_templates">
          <option value=[[field.id]] ng-repeat="field in templateSMSList" ng-selected="campaign_sms_templates.indexOf(field.id)!==-1">[[field.name]]</option>
          </select>


          It seems not a good practice but as I only want to save ids in my database documents so I did this.



          Any feedback are welcome.






          share|improve this answer













          After spending lots of time in this, now finally I have resolved this



          <select multiple="multiple" ng-change="save(campaign_sms_templates)" ng-model="campaign_sms_templates">
          <option value=[[field.id]] ng-repeat="field in templateSMSList" ng-selected="campaign_sms_templates.indexOf(field.id)!==-1">[[field.name]]</option>
          </select>


          It seems not a good practice but as I only want to save ids in my database documents so I did this.



          Any feedback are welcome.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 6:28









          ShadmanShadman

          4922817




          4922817























              0














              Use value.id as value.name for value:



              <select multiple="multiple"
              ng-model="campaign_sms_templates"
              ng-options="value.id as value.name for value in templateSMSList">
              </select>


              Also leave out the track by expression as it is not needed and will break the directive.



              For more information, see




              • AngularJS ng-options Directive API Reference - select as and track by.





              share|improve this answer



























                0














                Use value.id as value.name for value:



                <select multiple="multiple"
                ng-model="campaign_sms_templates"
                ng-options="value.id as value.name for value in templateSMSList">
                </select>


                Also leave out the track by expression as it is not needed and will break the directive.



                For more information, see




                • AngularJS ng-options Directive API Reference - select as and track by.





                share|improve this answer

























                  0












                  0








                  0







                  Use value.id as value.name for value:



                  <select multiple="multiple"
                  ng-model="campaign_sms_templates"
                  ng-options="value.id as value.name for value in templateSMSList">
                  </select>


                  Also leave out the track by expression as it is not needed and will break the directive.



                  For more information, see




                  • AngularJS ng-options Directive API Reference - select as and track by.





                  share|improve this answer













                  Use value.id as value.name for value:



                  <select multiple="multiple"
                  ng-model="campaign_sms_templates"
                  ng-options="value.id as value.name for value in templateSMSList">
                  </select>


                  Also leave out the track by expression as it is not needed and will break the directive.



                  For more information, see




                  • AngularJS ng-options Directive API Reference - select as and track by.






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 8:23









                  georgeawggeorgeawg

                  37.1k115473




                  37.1k115473



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330947%2fmap-ng-model-array-values-with-the-object-of-ng-options-for-selected-options%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해