Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default configuration #16

Closed
sylouuu opened this issue May 21, 2015 · 5 comments
Closed

Default configuration #16

sylouuu opened this issue May 21, 2015 · 5 comments

Comments

@sylouuu
Copy link

sylouuu commented May 21, 2015

Hey,

Thanks for ng-notify.

I'm wondering where do you put ngNotify.config()? In a controller?

For some other ng plugins that I've to use, all default options are inside:

app.config(function ($somethingProvider) {
    $somethingProvider.options({ ... });
});

But I can't inject ngNotify there, same in app.run().

So how do you do?

Bests

@jasmeetssalech
Copy link

Thanks for ng-Notify. Works like a charm.

I am having the same question as sylouuu

@matowens
Copy link
Owner

Hey guys, if you'd like to setup some default config options I'd recommend tossing it in the .run() block. There isn't much info from the docs on it, but here's a snippet.

A working example of setting it up this way:

<html ng-app="testApp">
<head>

    <link rel="stylesheet" type="text/css" href="ng-notify.min.css" />

</head>
<body ng-controller="homeController">

    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script src="ng-notify.min.js"></script>

    <script>

        // Intialize app.
        var app = angular.module('testApp', ['ngNotify']);

        // Set global config up on run.
        app.run([
            'ngNotify',
            function(ngNotify) {

                ngNotify.config({
                    position: 'top',
                    sticky: 'true'
                });
            }
        ]);

        // Use notify anywhere else.
        app.controller('homeController', [
            'ngNotify',
            function(ngNotify) {

                ngNotify.set('ngNotify default config options have been overriden.');

            }
        ])

    </script>

</body>
</html>

Here's an example you can play around with on codepen.

If you have a global controller, you could toss it in there as well. Hope this helps ya out!

@sylouuu
Copy link
Author

sylouuu commented May 22, 2015

@matowens You have right, my bad, it works in app.run().

But it's the first time I see a plugin configuration inside app.run() instead of app.config().

@gusbicalho
Copy link

The configuration is in .run() because the configuration methods are in the
service itself, not in the service's provider. That means you can change
the defaults while the app is running (in a Controller, for example), and
you can access other services when you do that.
In this case I don't think that's a bad idea. The provider should only be
used for configurations that have to happen before the app starts running.

On Fri, May 22, 2015 at 4:24 AM Syl [email protected] wrote:

@matowens https://github.com/matowens You have right, my bad, it works
in app.run().

But it's the first time I see a plugin configuration inside app.run()
instead of app.config().


Reply to this email directly or view it on GitHub
#16 (comment).

@sylouuu sylouuu closed this as completed May 22, 2015
@sureshanand
Copy link

very Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants