I think I have made some progress.
It is not exactly what is in the article. The doubt here is about
'deferred.reject'. That seems to working the same way as
'deferred.resolve'. Both flows print console.log( response );
----------------------------------------------------------------------------------------------------
resPromise =
AsynchronousService.asynchcall()
.then(ApiTransformer.apiTransformer);
resPromise.then(function(response) {
if (response) {
console.log( response );
}
});
----------------------------------------------------------------------------------------------------
factory('AsynchronousService', function( HEFactory,
$q,
ApiTransformer) {
return {
asynchcall:function() {
var deferred = $q.defer();
setTimeout(function() {
// Reject based on probability
if (Math.random() > 0.7) {
console.log('Rejected');
deferred.reject({ status: 'failure' });
} else {
deferred.resolve({ 'upperlimit' : 10, 'lowerlimit' : 5
});
}
}, 1000);
return deferred.promise;
}
};
----------------------------------------------------------------------------------------------------
factory('ApiTransformer', function( HEFactory,
$q) {
return {
apiTransformer:function(response) {
return HEFactory.serviceLimits(response);
}
};
});
----------------------------------------------------------------------------------------------------
Thanks,
Mohan
On Thursday, 12 February 2015 17:00:22 UTC+5:30, Mohan Radhakrishnan wrote:
>
> I understand what he is trying to explain up to a point.
>
> My asynchronous service is this.
>
> factory('AsynchronousService', function( HEFactory,
> $q) {
>
> return {
>
> asynchcall:function() {
>
> var deferred = $q.defer();
>
> setTimeout(function() {
>
> // Reject based on probability
> if (Math.random() > 0.7) {
>
> deferred.reject('Rejected');
>
> }
>
> else deferred.resolve('Succeeded');
>
> }, 1000);
>
> return deferred.promise;
> }
> };
>
> My functional constructor is this.
>
> function(serviceSpec){
>
> var thatserviceLimit = {};
>
> /** This attribute is currently bound by AngularJS
> * Af of now the corresponding setter 'setUpperLimit'
> * is not called by our AngularJS code. This may be
> * a limitation
> */
> thatserviceLimit.upperlimit = serviceSpec.upperlimit;
>
> thatserviceLimit.lowerlimit = serviceSpec.lowerlimit;
>
>
> thatserviceLimit.getUpperLimit = function(){
> return thatserviceLimit.upperlimit;
> };
>
> thatserviceLimit.getLowerLimit = function(){
> return thatserviceLimit.lowerlimit;
> };
>
> //thatserviceLimit.build = function(data){
> //return thatserviceLimit.lowerlimit;
> //};
>
> return thatserviceLimit;
> },
>
> The commented 'build' method is what I am trying to figure out.
>
>
> Mohan
>
> On Thursday, 12 February 2015 14:16:38 UTC+5:30, Sander Elias wrote:
>>
>> Hi Mohan,
>>
>> I think this article
>> <https://medium.com/opinionated-angularjs/angular-model-objects-with-javascript-classes-2e6a067c73bc>from
>>
>> my friend Geert will help you a bit.
>> If you still have questions after reading that, just ask!
>>
>> Regards
>> Sander
>>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.