$ scope.data is undefined, but $ scope.data exists in $ scope

I have javascript code:

 define(['controllers/controllers', 'services/alerts'], function(module) {
  'use strict';
  return module.controller('alerts', [
    '$scope', '$http', 'alerts', function($scope, $http, alerts) {
    console.log('alerts controller initialized');
    $scope.settings = {};
    return $scope.submit = function() {
      $scope.busy = true;
      console.log('scope', $scope);
      return console.log('data', $scope.data);
    };
  }
]);

});

I tried to write the contents $scope.data, which I assume will contain the values ng-model=> data.followers, but always shows undefined, but when I tried to write the contents of the value $scope, $scope.dataexists. As it shown on the picture:

the log

I tried to initialize $scope.data, but it will always return an empty array after changing the value of ng-model=> data.followers. This is the code (in haml) when I initialized ng-model:

 %input{:type => "checkbox", "ng-checked" => "settings.#{$key}", "ng-model" => "data.#{$key}", "ng-true-value" => "true", "ng-false-value" => "false", "ng-click" => "submit()"}

Any thoughts?

UPDATE:

Already fix it. All I did was initialize $ scope.data and the data used. # {$ Key} in ng verification. It made me stuck. Noob angular.

+3
1

Angular $scope.$apply(). Require - , $scope $digest Angular. $scope.$apply(), $digest .

, module.register.controller module.controller

define(['controllers/controllers', 'services/alerts'], function(module) {
  'use strict';
  return module.register.controller('alerts', [
    '$scope', '$http', 'alerts', function($scope, $http, alerts) {
    console.log('alerts controller initialized');
    $scope.settings = {};
    return $scope.submit = function() {
      $scope.busy = true;
      console.log('scope', $scope);
      return console.log('data', $scope.data);
    };
    $scope.$apply();
  }
]);
0

All Articles