2
$scope.form={
                Name:"",
                fields:[
                        {
                            id:"",
                            Name:"",
                            type:"dfsd",
                            order:""
                        }
                        ]
    };

How to access the type value in the above object.I need to push the value into it..i could not able to do..so first i thought to retrieve once I could not do..So can i have a solution for both the operations.Push and retrieve the value .

3
  • pls try this $scope.form.fields[0].type Commented Oct 20, 2015 at 6:18
  • Its working ...but we have to do looping right..and i need to push id,name,type,order to the fields.how to push all the four at a time to the fields ? Commented Oct 20, 2015 at 6:24
  • it's not really clear what it is you are trying to do here, exactly. are you trying to assign values from another object, or bind this to an HTML template, or something else? can you update the question with a sample of the code you have tried that didn't work? Commented Oct 20, 2015 at 6:35

1 Answer 1

1

use this code:::

$scope.savebutton = function() {
  angular.forEach($scope.textboxes, function(text) {

    if (text != undefined && text.length != 0) {
      inputs = [];
      angular.forEach($scope.textboxes, function(t) {
        inputs.push(t);
      });
    }
  });
  var textfield = {
    id: "1",
    Name: "textbox"
  }


  $scope.form = {};
  $scope.form.fields = [];

  $scope.form.fields.push(textfield);
  console.log(angular.toJson($scope.form));
  ngDialog.closeAll();
};
Sign up to request clarification or add additional context in comments.

3 Comments

I am getting an error when i use that statement. Cannot read property 'push' of undefined
you are getting this error because you couldn't create '$scope.form.fields' before 'push'
you have to create "$scope.form.fields" before pushing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.