ngProgress icon indicating copy to clipboard operation
ngProgress copied to clipboard

ngProgress injected is not the service but the factory

Open toutpt opened this issue 8 years ago • 6 comments

capture d ecran 2016-05-24 a 11 38 13

That is weird I have installed it that way:

package.json

"ngprogress": "VictorBjelkholm/ngProgress#v1.1.3",

then include resources:

            "node_modules/ngprogress/build/ngProgress.min.js",
            "node_modules/ngprogress/ngProgress.css",

app.js

angular.module('swif.framework', [...
    'ngProgress',
]);

the controller is on the screen shot

Was working on 1.0.7, do not work on 1.1.3 (also tried on 1.1.1)

Any idea ? I think this has to be with the way you handle injection.

You should name the function and then add $inject property on it.

function ngProgressFactory(x,y,z) {} ngProgressFactory.$inject('x','y','z'); Because you use a factory and return ['x', f(x) {}] I get that array instead of the service.

toutpt avatar May 24 '16 09:05 toutpt

I'd need to see your controller to find out what is going wrong

You should inject the ngProgressFactory:

var MainCtrl = function($scope, $timeout, ngProgressFactory) {}

Then in your controller's function, create an instance of ngProgress:

$scope.progressbar = ngProgressFactory.createInstance();

cetra3 avatar May 25 '16 07:05 cetra3

I think it's more a bug than a question because it works on 1.0.

I have injected 'ngProgress' into the controller:

function msgService($uibModal, notificationService, ngProgress, errorMsgService, gettextCatalog) {
    'ngInject';
    ...
    cf capture for the code

If I look to the source: https://github.com/VictorBjelkholm/ngProgress/blob/master/src/provider.js#L3

.service('ngProgress', function () {

So It should be possible to use 'ngProgress' but it's not. Because it returns something that is not a service:

return ['$document', '$window', '$compile', '$rootScope', '$timeout', function($document, $window, $c

And as I said It works on the 1.0 but not on the 1.1 and I have found the commit that broke my code:

https://github.com/VictorBjelkholm/ngProgress/commit/f888e28b2f3dd8c917c1b2c7a416c4b7787db537

So it means 'ngProgress' is not a service anymore ?

Now I need to change from 'ngProgress' to 'ngProgressFactory', create an instance and put it into the scope. You may add a note for this migration path from 1.0 to 1.1 or fix it to be usable as a service.

toutpt avatar May 25 '16 07:05 toutpt

Yeah, it may be worthwhile as a note in the readme for upgrading. I have a feeling it was changed to allow multiple instances of ngProgress at any given time.

cetra3 avatar May 25 '16 07:05 cetra3

A question, do that work on 1.0 ?

--- a/src/framework/messages.js
+++ b/src/framework/messages.js
@@ -106,9 +106,10 @@
     * @name swif.framework.msgService
     * @description this service provide an API to display feedback to the user.
     **/
-    function msgService($uibModal, notificationService, ngProgress, errorMsgService, gettextCatalog) {
+    function msgService($uibModal, notificationService, ngProgressFactory, errorMsgService, gettextCatalog) {
         'ngInject';
         var messages = [];
+        var ngProgress = ngProgressFactory.createInstance();

toutpt avatar May 25 '16 07:05 toutpt

I understand, adding features is always great but breaking changes are bad (at least 1.0 -> 1.1 should be minor changes).

To handle this I'm using https://github.com/semantic-release/semantic-release which pump major release depending on your commit message and that is great !

toutpt avatar May 25 '16 08:05 toutpt

Yep, agree. This was before my time. Glad to have solved the mystery though.

cetra3 avatar May 25 '16 08:05 cetra3