Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(Module): allow passing template/templateUrl in array notation #13485

Closed
wants to merge 1 commit into from
Closed

fix(Module): allow passing template/templateUrl in array notation #13485

wants to merge 1 commit into from

Conversation

shahata
Copy link
Contributor

@shahata shahata commented Dec 9, 2015

No description provided.

@gkalpak
Copy link
Member

gkalpak commented Dec 10, 2015

LGTM

@@ -362,7 +362,7 @@ function setupModuleLoader(window) {
component: function(name, options) {
function factory($injector) {
function makeInjectable(fn) {
if (angular.isFunction(fn)) {
if (isFunction(fn) || isArray(fn)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure we cannot rely on being in the closure of angular here.
Although the unit tests will pass, I don't think that isFunction and isArray will be available in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFunction is used further down in the same file, so it means we're fine, no? https://github.com/angular/angular.js/blob/master/src/loader.js#L454

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see that working in practice before I agree... I wonder if that other use ever worked... :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That usage was added by an external committer... 351fe4b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that line didn't work every single service/directive/etc. you define would throw... (btw, it also has a bug of not handling array notation 😄)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you just do angular.isArray you would break the loader as it is meant to be run without angular

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an open issue about the loader being broken for certain modules. Maybe that already happens?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.isArray is supported on all the browsers that we support in (outside of v1.2) (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#Browser_compatibility) so should just use that in this case...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely have a comment at the top of this file, explaining where we get isFunction from.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petebacondarwin in 99% of the cases (that is when people use angular and not just the loader), isFunction comes from src/Angular.js and I doubt that there is a need to explain this. For the 1% of cases that the loader is used stand-alone, then it comes from another place.

@Narretz
Copy link
Contributor

Narretz commented Dec 10, 2015

I feel like this should be documented, no?

@Narretz Narretz added this to the 1.5.0-rc.1 milestone Dec 10, 2015
@Narretz
Copy link
Contributor

Narretz commented Dec 11, 2015

Also, what's the reason why component() itself is not injectable?

@gkalpak
Copy link
Member

gkalpak commented Dec 12, 2015

component() does not accept a factory function, it gets the CDO (Component Definition Object 😄) directly.
Although, I've been thinking it might be convenient to overload it, in order to also accept a factory function.

@petebacondarwin
Copy link
Contributor

I think it is nice that we are not injecting into the CDO. Anything that needs injection can ask for it.

@Narretz
Copy link
Contributor

Narretz commented Dec 20, 2015

I'd still like to see a mention in the docs that you can you can inject any injectables into the template / templateUrl fn. This is far from obvious.

@lgalfaso
Copy link
Contributor

@Narretz do you want to open an issue to track that?

@Narretz
Copy link
Contributor

Narretz commented Dec 20, 2015

@lgalfaso I've added this to the docs just now, but I would really prefer if docs landed as part of the code changes.

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

Successfully merging this pull request may close these issues.

6 participants