Pass different array every time in ng-repeat












0















I am generating comboboxes dynamically and I need to pass a different collection to the ng-repeat every time.How can I do that?



<div ng-repeat="choice in $ctrl.inputFilterRows">
<md-select ng-model="choice.name">
<md-option ng-repeat="filter in $ctrl.filters" value="{{filter.value}}" >
{{filter.value}}
</md-option>
</md-select>
</div>


Tried to set from the controller, but didnt work:



self.inputFilterRows[0].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];









share|improve this question





























    0















    I am generating comboboxes dynamically and I need to pass a different collection to the ng-repeat every time.How can I do that?



    <div ng-repeat="choice in $ctrl.inputFilterRows">
    <md-select ng-model="choice.name">
    <md-option ng-repeat="filter in $ctrl.filters" value="{{filter.value}}" >
    {{filter.value}}
    </md-option>
    </md-select>
    </div>


    Tried to set from the controller, but didnt work:



    self.inputFilterRows[0].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];









    share|improve this question



























      0












      0








      0








      I am generating comboboxes dynamically and I need to pass a different collection to the ng-repeat every time.How can I do that?



      <div ng-repeat="choice in $ctrl.inputFilterRows">
      <md-select ng-model="choice.name">
      <md-option ng-repeat="filter in $ctrl.filters" value="{{filter.value}}" >
      {{filter.value}}
      </md-option>
      </md-select>
      </div>


      Tried to set from the controller, but didnt work:



      self.inputFilterRows[0].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];









      share|improve this question
















      I am generating comboboxes dynamically and I need to pass a different collection to the ng-repeat every time.How can I do that?



      <div ng-repeat="choice in $ctrl.inputFilterRows">
      <md-select ng-model="choice.name">
      <md-option ng-repeat="filter in $ctrl.filters" value="{{filter.value}}" >
      {{filter.value}}
      </md-option>
      </md-select>
      </div>


      Tried to set from the controller, but didnt work:



      self.inputFilterRows[0].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];






      javascript angularjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 10:31









      Dimitrios Matanis

      5381314




      5381314










      asked Nov 20 '18 at 13:20









      Lio ProgramistaLio Programista

      618




      618
























          1 Answer
          1






          active

          oldest

          votes


















          1














          An idea would be to use ng-if on several md-select elements and decide which one to enable based on a condition that suits you.



          Another is to have a $scope variable that is linked to a single ng-repeat select, but you keep assigning new values to that $scope variable collection whenever you want. That would force a scope redraw and the ng-repeat would now use the new collection values.



          Second one is probably cleaner.



          EDIT:



          Based on a better explanation provided in the comments below I now realise that you want a set of selects, each with their own set of options.



          To achieve something like that I would suggest having an array of arrays, in which each object would represent a select, and then it's contents would be the options for that select.



          $scope.selectArray = [
          { name: 'colours', filters: [{ value: 'black' }, { value: 'red' }, { value: 'blue' }] },
          { name: 'months', filters: [{ value: 'January' }, { value: 'February' }, { value: 'March' }] }
          ];


          Now, you can have an ng-repeat iterating over selectArray (select in selectArrays) to create the selects, and then each one would contain another ng-repeat to iterate over the select.filters (filter in select.filters)



          I am not going to write the exact code because you look like you know what you're doing and I'm sure you can put it together yourself very easily.



          If you want to change the dataset of a specific select you can do something like:



          $scope.selectArray[1].filters[0].value = 'December';


          or



          $scope.selectArray[1].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];





          share|improve this answer


























          • Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

            – Lio Programista
            Nov 20 '18 at 13:36













          • The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

            – Dimitrios Matanis
            Nov 20 '18 at 13:37











          • But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

            – Lio Programista
            Nov 20 '18 at 13:41













          • Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

            – Dimitrios Matanis
            Nov 20 '18 at 13:45











          • Yes, I am adding the combo boxes dynamically. I have two ng-repeats

            – Lio Programista
            Nov 20 '18 at 13:47











          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%2f53393916%2fpass-different-array-every-time-in-ng-repeat%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          An idea would be to use ng-if on several md-select elements and decide which one to enable based on a condition that suits you.



          Another is to have a $scope variable that is linked to a single ng-repeat select, but you keep assigning new values to that $scope variable collection whenever you want. That would force a scope redraw and the ng-repeat would now use the new collection values.



          Second one is probably cleaner.



          EDIT:



          Based on a better explanation provided in the comments below I now realise that you want a set of selects, each with their own set of options.



          To achieve something like that I would suggest having an array of arrays, in which each object would represent a select, and then it's contents would be the options for that select.



          $scope.selectArray = [
          { name: 'colours', filters: [{ value: 'black' }, { value: 'red' }, { value: 'blue' }] },
          { name: 'months', filters: [{ value: 'January' }, { value: 'February' }, { value: 'March' }] }
          ];


          Now, you can have an ng-repeat iterating over selectArray (select in selectArrays) to create the selects, and then each one would contain another ng-repeat to iterate over the select.filters (filter in select.filters)



          I am not going to write the exact code because you look like you know what you're doing and I'm sure you can put it together yourself very easily.



          If you want to change the dataset of a specific select you can do something like:



          $scope.selectArray[1].filters[0].value = 'December';


          or



          $scope.selectArray[1].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];





          share|improve this answer


























          • Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

            – Lio Programista
            Nov 20 '18 at 13:36













          • The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

            – Dimitrios Matanis
            Nov 20 '18 at 13:37











          • But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

            – Lio Programista
            Nov 20 '18 at 13:41













          • Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

            – Dimitrios Matanis
            Nov 20 '18 at 13:45











          • Yes, I am adding the combo boxes dynamically. I have two ng-repeats

            – Lio Programista
            Nov 20 '18 at 13:47
















          1














          An idea would be to use ng-if on several md-select elements and decide which one to enable based on a condition that suits you.



          Another is to have a $scope variable that is linked to a single ng-repeat select, but you keep assigning new values to that $scope variable collection whenever you want. That would force a scope redraw and the ng-repeat would now use the new collection values.



          Second one is probably cleaner.



          EDIT:



          Based on a better explanation provided in the comments below I now realise that you want a set of selects, each with their own set of options.



          To achieve something like that I would suggest having an array of arrays, in which each object would represent a select, and then it's contents would be the options for that select.



          $scope.selectArray = [
          { name: 'colours', filters: [{ value: 'black' }, { value: 'red' }, { value: 'blue' }] },
          { name: 'months', filters: [{ value: 'January' }, { value: 'February' }, { value: 'March' }] }
          ];


          Now, you can have an ng-repeat iterating over selectArray (select in selectArrays) to create the selects, and then each one would contain another ng-repeat to iterate over the select.filters (filter in select.filters)



          I am not going to write the exact code because you look like you know what you're doing and I'm sure you can put it together yourself very easily.



          If you want to change the dataset of a specific select you can do something like:



          $scope.selectArray[1].filters[0].value = 'December';


          or



          $scope.selectArray[1].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];





          share|improve this answer


























          • Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

            – Lio Programista
            Nov 20 '18 at 13:36













          • The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

            – Dimitrios Matanis
            Nov 20 '18 at 13:37











          • But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

            – Lio Programista
            Nov 20 '18 at 13:41













          • Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

            – Dimitrios Matanis
            Nov 20 '18 at 13:45











          • Yes, I am adding the combo boxes dynamically. I have two ng-repeats

            – Lio Programista
            Nov 20 '18 at 13:47














          1












          1








          1







          An idea would be to use ng-if on several md-select elements and decide which one to enable based on a condition that suits you.



          Another is to have a $scope variable that is linked to a single ng-repeat select, but you keep assigning new values to that $scope variable collection whenever you want. That would force a scope redraw and the ng-repeat would now use the new collection values.



          Second one is probably cleaner.



          EDIT:



          Based on a better explanation provided in the comments below I now realise that you want a set of selects, each with their own set of options.



          To achieve something like that I would suggest having an array of arrays, in which each object would represent a select, and then it's contents would be the options for that select.



          $scope.selectArray = [
          { name: 'colours', filters: [{ value: 'black' }, { value: 'red' }, { value: 'blue' }] },
          { name: 'months', filters: [{ value: 'January' }, { value: 'February' }, { value: 'March' }] }
          ];


          Now, you can have an ng-repeat iterating over selectArray (select in selectArrays) to create the selects, and then each one would contain another ng-repeat to iterate over the select.filters (filter in select.filters)



          I am not going to write the exact code because you look like you know what you're doing and I'm sure you can put it together yourself very easily.



          If you want to change the dataset of a specific select you can do something like:



          $scope.selectArray[1].filters[0].value = 'December';


          or



          $scope.selectArray[1].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];





          share|improve this answer















          An idea would be to use ng-if on several md-select elements and decide which one to enable based on a condition that suits you.



          Another is to have a $scope variable that is linked to a single ng-repeat select, but you keep assigning new values to that $scope variable collection whenever you want. That would force a scope redraw and the ng-repeat would now use the new collection values.



          Second one is probably cleaner.



          EDIT:



          Based on a better explanation provided in the comments below I now realise that you want a set of selects, each with their own set of options.



          To achieve something like that I would suggest having an array of arrays, in which each object would represent a select, and then it's contents would be the options for that select.



          $scope.selectArray = [
          { name: 'colours', filters: [{ value: 'black' }, { value: 'red' }, { value: 'blue' }] },
          { name: 'months', filters: [{ value: 'January' }, { value: 'February' }, { value: 'March' }] }
          ];


          Now, you can have an ng-repeat iterating over selectArray (select in selectArrays) to create the selects, and then each one would contain another ng-repeat to iterate over the select.filters (filter in select.filters)



          I am not going to write the exact code because you look like you know what you're doing and I'm sure you can put it together yourself very easily.



          If you want to change the dataset of a specific select you can do something like:



          $scope.selectArray[1].filters[0].value = 'December';


          or



          $scope.selectArray[1].filters = [{ value: 'June' }, { value: 'July' }, { value: 'August' }];






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 8:58

























          answered Nov 20 '18 at 13:23









          Dimitrios MatanisDimitrios Matanis

          5381314




          5381314













          • Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

            – Lio Programista
            Nov 20 '18 at 13:36













          • The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

            – Dimitrios Matanis
            Nov 20 '18 at 13:37











          • But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

            – Lio Programista
            Nov 20 '18 at 13:41













          • Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

            – Dimitrios Matanis
            Nov 20 '18 at 13:45











          • Yes, I am adding the combo boxes dynamically. I have two ng-repeats

            – Lio Programista
            Nov 20 '18 at 13:47



















          • Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

            – Lio Programista
            Nov 20 '18 at 13:36













          • The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

            – Dimitrios Matanis
            Nov 20 '18 at 13:37











          • But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

            – Lio Programista
            Nov 20 '18 at 13:41













          • Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

            – Dimitrios Matanis
            Nov 20 '18 at 13:45











          • Yes, I am adding the combo boxes dynamically. I have two ng-repeats

            – Lio Programista
            Nov 20 '18 at 13:47

















          Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

          – Lio Programista
          Nov 20 '18 at 13:36







          Thank you. How can I dynamically generate the scope variable name and link it to the ng-repeat?

          – Lio Programista
          Nov 20 '18 at 13:36















          The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

          – Dimitrios Matanis
          Nov 20 '18 at 13:37





          The scope variable name will always be the same. You will just keep assigning different sets of data to it. As an example lets assume $scope.collection, which can start with $scope.collection = A_LIST_OF_COLOURS and then later on $scope.collection = A_LIST_OF_MONTHS. The ng-repeat will always be bound to $scope.collection

          – Dimitrios Matanis
          Nov 20 '18 at 13:37













          But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

          – Lio Programista
          Nov 20 '18 at 13:41







          But in this case dont you think that the last assign collection will be the collection for all drop downs because all of them are with the same name. I thought that I need to do something like '<md-option ng-repeat="filter in $ctrl.filters{{$index}}" value="{{filter.value}}" >'

          – Lio Programista
          Nov 20 '18 at 13:41















          Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

          – Dimitrios Matanis
          Nov 20 '18 at 13:45





          Oh I was under the impression that you had one select and your ng-repeat was for the options of that. At least that's what your code shows. Do you have 2 ng-repeats? One to create many md-selects and then one for the options of each one?

          – Dimitrios Matanis
          Nov 20 '18 at 13:45













          Yes, I am adding the combo boxes dynamically. I have two ng-repeats

          – Lio Programista
          Nov 20 '18 at 13:47





          Yes, I am adding the combo boxes dynamically. I have two ng-repeats

          – Lio Programista
          Nov 20 '18 at 13:47




















          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%2f53393916%2fpass-different-array-every-time-in-ng-repeat%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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()