angularjs - Angular submit a preset input value -


i'm having trouble submitting preset value. if type in input gets submitted fine. if not value showing undefined. if set array values @ beginning before controller shown in page , gets submitted. if initialize array populate dynamically submits empty arry not shown on page.

i know it's weird angular $scope issue i've been trying days debug unsuccessfully. can find problem?

 <button type="button" class="btn btn-primary" form="commandform" ng-click="submitcmd(mycommand)">                          <tr ng-repeat="param in paramlist">                         <td></td>                         <td><input type="text" id="paramname"                                                class="hidden_text"                                                ng-model="mycommand.paramnames[$index]"                                                ng-readonly="false"                                                ng-value="param.name"                                                ng-disabled="!checked" />                         </td> app.controller('commandcontroller', function($scope, $http, $location,     restangular, $q) {  $scope.mycommand = {};  $scope.mycommand.paramnames = [];   ///if set =["one","two"] works ( statically cannot dynamically set values )  /* list below gets fed backend , displays    correctly on page  $scope.paramlist = {}; 

//in method below mycommand has empty array of paramnames described above...

    $scope.submitcmd = function(mycommand) {     /*      * fresh data sent page      */      console.log(">>>>>>>>>look>>>>>>>submitcmd(mycommand): "             + angular.tojson(mycommand, 2)); 

i've tried taking $scope.mycommand instead of passing model mycommand page. same results.

i believe problem has following...

( idea how bind ng-model object have same scope when retrieve in controller ( page )?

from angular documentation:

for each item/iteration, ng-repeat creates new scope, prototypically inherits parent scope, assigns item's value new property on new child scope. (the name of new property loop variable's name.) here's angular source code ng-repeat is:

childscope = scope.$new(); // child scope prototypically inherits parent scope ...
childscope[valueident] = value; // creates new childscope property

if item primitive (as in myarrayofprimitives), copy of value assigned new child scope property. changing child scope property's value (i.e., using ng-model, hence child scope property num) not change array parent scope references. in first ng-repeat above, each child scope gets num property independent of myarrayofprimitives array:

ng-repeat primitive

this ng-repeat not work (like want/expect to). in angular 1.0.2 or earlier, typing textboxes changes values in gray boxes, visible in child scopes. in angular 1.0.3+, typing text boxes has no effect. (see artem's explanation why on stackoverflow.) want inputs affect myarrayofprimitives array, not child scope primitive property. accomplish this, need change model array of objects.

so, if item object, reference original object (not copy) assigned new child scope property. changing child scope property's value (i.e., using ng-model, hence obj.num) change object parent scope references. in second ng-repeat above, have:

ng-repeat object

this works expected. typing textboxes changes values in gray boxes, visible both child , parent scopes.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -