我想從這個$範圍內做一個簡單的console.log()
:
<div ng-controller="CustomerController" id="customer-block">
<h3>Customer Information</h3>
<div class="col-md-4">
<label>Address 1:</label>
<input type="text" ng-model="customer.address1" class="form-content"
id="customer-address1" />
</div>
<div class="col-md-4">
<label>Address 2:</label>
<input type="text" ng-model="customer.address2" class="form-content"
id="customer-address2" />
</div>
<div class="col-md-4">
<label>City</label>
<input type="text" ng-model="customer.city" class="form-content"
id="customer-city" />
</div>
</div>
這是我的JavaScript文件:
lima3app.controller("CustomerController", function($scope){
console.log($scope.customer);
});
但該日誌返回給我undefined。那有什麼問題?
這是plunkr:http://plnkr.co/edit/MU2i46o03bs22Jwh6QIe
'$ scope.customer'沒有在任何地方初始化,所以它應該是未定義的。在這些輸入中輸入內容後,它將開始有數據。 – runTarm