AngularJS - Simple $scope console.log() returns undefined

前端 未结 2 763
说谎
说谎 2021-01-11 20:48

I\'m trying to make a simple console.log() from this $scope:

2条回答
  •  暖寄归人
    2021-01-11 21:49

    As the others have said, you need to initialize the customer object.

    Since there is no value of customer set from controller, it is appearing as undefined in the view. When you enter values in the input boxes, this will no longer be undefined, but since logging is done only once initially, typing values in input box has no effect

    Plunker Demo

    Here is the part which I have changed in script.js

    lima3app.controller("CustomerController", function($scope){
    
    $scope.customer = {
      address1 : 'address1',
      address2 : 'address2',
      city:'city'
    }
    
    console.log($scope.customer);
    
    });
    

提交回复
热议问题