i am learning angular and that is why some time i get stuck to understand the code. i got a code for custom service in angular. see the code first.
angular.module('yourModule').factory('alertService', function() {
return {
showError : function() {
$.bigBox({
title: title,
content: content == null ? "An error occurred.<br /><br />If this error persists, please contact support." : content,
color: "#C46A69",
//timeout: 6000,
icon: "fa fa-warning shake animated",
//number: "1",
timeout: 3000
});
}
};
});
Then you can inject it inside any controller and use it:
angular.module('yourModule').controller('yourController', function($scope, alertService) {
someFunction().success(function (result) {
// great!
}).error(function (error) {
// call standard error message function
alertService.showError("Update Failed"); // use default error message
});
});
question 1
when injecting inbuilt service then we use $ sign like this way $scope or $window etc but when injecting custom one then just write the service name without $ sign why?
if we need to inject my own service with $ sign then any problem would occur ? for $ sign do i need to create service with any specific code pattern ?
question 2
showError : function() {
}
can we declare the above function name like this way
this.showError = function() {
};
$scope.showError = function() {
}
please rectify me if there is problem in my understanding.