angular material - AngularJS: Not able to store data to an object -


i'm trying store captured data form in object using angular-material dialog box form capture.

related part of controller looks like

  $scope.attendees = [{     firstname: "",     lastname: "",     email: "",     phone: ""    }];    $scope.addattendee = function(ev) { $mddialog.show({ controller: dialogcontroller, templateurl: 'views/regform.tmpl.html', parent: angular.element(document.body), targetevent: ev, clickoutsidetoclose:true, fullscreen: $scope.customfullscreen // -xs, -sm breakpoints. }) };      function dialogcontroller($scope, $mddialog) {                 $scope.hide = function() {                   $mddialog.hide();                 };                  $scope.cancel = function() {                   $mddialog.cancel();                 };                  $scope.saveattendee = function(attendee) {                    str = json.stringify(attendee, null, 4);                   $mddialog.hide(attendee);                    console.log('attendee ' + str);                    $scope.attendees.push(attendee);                    console.log('attendees ' + $scope.attendees);                 };               } 

output attendee correct later crashed on push(attendee) cannot read property 'push' of undefined or push overwrite added data (based on given answer)

any tips on that?

just move $scope.attendees inside controller.

function dialogcontroller($scope, $mddialog) {  $scope.attendees = [{  firstname: "",  lastname: "",  email: "",  phone: "" }];       $scope.hide = function() {   $mddialog.hide(); };  $scope.cancel = function() {   $mddialog.cancel(); };  $scope.saveattendee = function(attendee) {    str = json.stringify(attendee, null, 4);   $mddialog.hide(attendee);    console.log('attendee ' + str);    $scope.attendees.push(attendee);    console.log('attendees ' + $scope.attendees); }; } 

what saying send data controller calls mddialog, alld plnkr basic example. example plnkr

cour code modificated should be.

function dialogcontroller($scope, $mddialog, attendees) {     $scope.attendees = attendees;     $scope.hide = function() {       $mddialog.hide();     };     $scope.cancel = function() {       $mddialog.cancel();     };     $scope.saveattendee = function(attendee) {       str = json.stringify(attendee, null, 4);       $mddialog.hide(attendee);       console.log('attendee ' + str);       $scope.attendees.push(attendee);       console.log('attendees ' + $scope.attendees);     };   } 

and in controller calls example

$modal.show({  // configuration have. }).then(function(response){    //when hide modal    $scope.attendees = response; }); 

check if out if help.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -