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

factory and controller #2

Open
gg4u opened this issue Nov 15, 2014 · 1 comment
Open

factory and controller #2

gg4u opened this issue Nov 15, 2014 · 1 comment

Comments

@gg4u
Copy link

gg4u commented Nov 15, 2014

Could you also please explain the meaning of:
function($q, elasticsearch, $location)

you pass to the factory?

and:
function(recipes, $scope, $location)
you pass to the controller?

I got the sense you pass a value from the controller to the factory, is it that?
(from input search field, to factory, which produces the obj of results)
But I didn't understand how is done exactly.

Also,
what's the need of:
['$locationProvider', function($locationProvider){
$locationProvider.html5Mode(true);
}]

in the module?
I read your blog but didn't understand these passages.

Thank you!

@adambard
Copy link
Owner

The factory is just a function that constructs a service object, which sounds fancier than it is; in this case, the returned service is called "recipeService" and the returned service looks like:

        return {
            "search": search
        };

where search is the function defined immediately above this line that actually does the searching.

Then, the controller has access to recipeService, which it uses to actually perform the search. All this could be defined within the controller perfectly well, it's just a matter of separating the api from the implementation.

HTML5 mode just lets you use URLs that look like example.com/my/path instead of example.com/#/my/path, and I think it also gives better access to query parameters, I can't really remember.

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

2 participants