2015-09-30 69 views
1

我無法在控制器中使用$ scope.data,它是未定義的,您能幫忙嗎?

感謝

contact.html

<textarea cols="40" rows="6" name="message" id="message" class="panelInputs" placeholder="Message" ng-model="data.message" ng-change="displayscope()"></textarea> 

controllers.js

angular.module('BoardLine.controllers', ['BoardLine.services']) 
.controller('ContactCtrl', function($scope, $stateParams, sessionService, isPhoneGap, isIOS) { 
    console.log($scope.data); 
    $scope.displayscope = function() { 
    console.log("displayscope : "); 
    console.log($scope.data); 
    } 
}) 

app.js

angular.module('BoardLine', ['ionic', 'ngCookies', 'ui.unique', 'BoardLine.controllers', 'BoardLine.services', 'BoardLine.filters']) 

回答

4

您需要定義屬性data像首先在您的控制器中使用$scope.data = {}。因爲ng-model綁定到data.message,而dataundefined。因此無法分配message

2

在你的控制器,你應該聲明$ scope.date對象

angular.module('BoardLine.controllers', ['BoardLine.services']) 
.controller('ContactCtrl', function($scope, $stateParams, sessionService, isPhoneGap, isIOS) { 
//add this 
$scope.data = {}; 

    console.log($scope.data); 
    $scope.displayscope = function() { 
    console.log("displayscope : "); 
    console.log($scope.data); 
    } 
})