Is it considered better practice to use a custom object vs $scope properties in AngularJS controllers?
Or is it better to attach the plateCheck properties to the $scope of the controller?
Object Version
app.controller('PlateCheckCtrl', ['$scope', 'PlateCheckService', function ($scope, PlateCheckService) {
var plateCheck = {
plateNumber: '',
message: '',
alertClass: '',
checkPlate: function (plateNumber) {
var _this = this;
PlateCheckService.checkPlate(plateNumber).then(function (response) {
_this.message = response.message;
_this.alertClass = response.alertClass;
});
}
};
$scope.plateCheck = plateCheck;
}]);
$scope Version
app.controller('PlateCheckCtrl', ['$scope', 'PlateCheckService', function ($scope, PlateCheckService) {
$scope.plateNumber = '';
$scope.message = '';
$scope.alertClass = '';
$scope.checkPlate: function (plateNumber) {
PlateCheckService.checkPlate(plateNumber).then(function (response) {
$scope.message = response.message;
$scope.alertClass = response.alertClass;
});
};
}]);
I thought I had read somewhere that if you were not referencing your $scope objects/properties with a . you were doing it wrong.
<input type="text" data-ng-model="object.property" /> <-- Right Way
<input type="text" data-ng-model="property" /> <-- Wrong Way