I'm new at angular and node so I have some problems.
I don't get what $scope do exactly and I don't know how to use it.
When I wrote the code like this, it didn't work
angular.module('app', [])
.controller('settingsCtrl', ['$scope',
function($scope) {
//define the date format
$scope.date= new Date();
$scope.h = date.getHours();
$scope.m = date.getMinutes();
if(6 < $scope.h < 14 && 0 < $scope.m < 60){
$scope.text='Ok';
}
}]);
But when I wrote it like that, it works.
angular.module('app', [])
.controller('settingsCtrl', ['$scope',
function($scope) {
//define the date format
var date= new Date();
$scope.h = date.getHours();
$scope.m = date.getMinutes();
if(6 < $scope.h < 14 && 0 < $scope.m < 60){
$scope.text='Ok';
}
}]);
And this is the HTML code
<div data-ng-controller="settingsCtrl">
<div class="card">
<div class="card-header ">
<p>{{date | date}}</p>
</div>
<div class="card-block">
<p>{{h}}</p>
<p>{{m}}</p>
<p>{{text}}</p>
</div>
</div>
</div>
Can anyone explain to me what is the difference between the two codes and how to get familiar with the $scope ?
Thanks
$scopein favour of the 'controllerAs' syntax these days. Also, if you have any choice in the matter, I'd really recommend learning a more modern framework than Angular 1 (Angular 4, React and Vue are all good options).it didn't workexactly mean? Any error? Log? Could you be more specific, please?