1

I can't use $scope.data in my controller, it's undefined, can you help please ?

Thanks

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'])

2 Answers 2

4

You need to define the property data like $scope.data = {} in your controller first. Because your ng-model binds to data.message, while data is undefined. So the message cannot be assigned.

Sign up to request clarification or add additional context in comments.

Comments

2

In your controller you should declare $scope.date object

    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);
  }
})

Comments

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.