I am brand new in AngularJS and I will learn it in a tutorial. I have doubts about using factory in Angular.
I know that factory is a template used to create objects on demand.
So, in the example there is the following code:
angular.module("myApp")
.value("testValue", "AngularJS Udemy")
.factory("courseFactory", function(testValue) {
var courseFactory = {
'courseName': testValue,
'author': 'Tuna Tore',
getCourse: function(){
alert('Course: ' + this.courseName);
}
};
return courseFactory;
})
.controller("factoryController", function($scope, courseFactory) {
alert(courseFactory.courseName);
$scope.courseName = courseFactory.courseName;
console.log(courseFactory.courseName);
courseFactory.getCourse();
});
And this is the code associated with this factoryController inside the HTML page:
<div ng-controller="factoryController">
{{ courseName }}
</div>
So it's pretty clear to me that:
factoryController uses courseFactory factory because it is being introduced
The first thing that happens when I open the page is that an error message is displayed because it is called:
alert(courseFactory.courseName);
$scope.courseName ( $scope) ** courseName courseFactory JSON).
. , factory :
.factory("courseFactory", function(testValue)
, ( , ), factory courseFactory , courseFactory JSON .
, ( Java), Java factory, , factory. , :
$scope.courseName = courseFactory.courseName;
, _ courseFactory JSON, courseFactory.
? getter factory? ( - )