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

Can't upgrade from beta.7 to beta.8-10 #7709

Closed
ifyify opened this issue Jun 5, 2014 · 21 comments
Closed

Can't upgrade from beta.7 to beta.8-10 #7709

ifyify opened this issue Jun 5, 2014 · 21 comments

Comments

@ifyify ifyify changed the title Are you will filterProvider or something? Can't upgrade from beta.7 to beta.8-10 Jun 5, 2014
@lgalfaso
Copy link
Contributor

lgalfaso commented Jun 5, 2014

Hi,
Any chance you can create an example (e.g using http://plnkr.co) ?

@Narretz
Copy link
Contributor

Narretz commented Jun 5, 2014

beta.8 includes a breaking change regarding provider registration, see

https://github.com/angular/angular.js/blob/master/CHANGELOG.md#130-beta8-accidental-haiku-2014-05-09

Maybe that's related?

@ifyify
Copy link
Author

ifyify commented Jun 17, 2014

Same on beta13.

The core of issue was attempt to register new filter in third party library.

angular.module('ng').filter('tel', function (){});

There are few libraries with behavior like this. It will be great to add init/lock life cycle and say directly that ng module is prohibited for extension.

@caitp
Copy link
Contributor

caitp commented Jun 17, 2014

Please post a repro, it's possible that it's a regression

@caitp
Copy link
Contributor

caitp commented Jun 17, 2014

Nevermind, I can reproduce this with http://plnkr.co/edit/txehajjSSoMV71at9Ygc?p=preview

I'll look into this today

@caitp caitp self-assigned this Jun 17, 2014
@caitp
Copy link
Contributor

caitp commented Jun 17, 2014

The reason this happens is because now, $providers are always run before config blocks --- however in the case of the ng module, all of the work is actually done in a config block, so this breaks. (This is because of the commit @Narretz is referencing)

This is a breaking change that wasn't mentioned in the changelog, unfortunately.

@caitp
Copy link
Contributor

caitp commented Jun 17, 2014

Anyways, I'll put together a fix for this (but I'm not sure "extending" the ng module was ever really a supported use case)

caitp added a commit to caitp/angular.js that referenced this issue Jun 17, 2014
…/etc

Due to a regression in c0b4e2d, it is no longer possible to add new controllers, directives,
filters, or animations to the `ng` module. This is becuase `config` blocks are always
evaluated after regular invoke blocks, and the registration of these types depend on angular's
config blocks to have been run.

This solution simply ensures that `ng`'s config blocks are run before its invoke blocks are run.

Closes angular#7709
@btford
Copy link
Contributor

btford commented Jun 20, 2014

There are few libraries with behavior like this.

@ifyify I feel like this falls under the category of "probably not the best way to do things." What are the 3rd party libraries that do this? If they are open source and on GitHub, I'd like to file issues against them.

@caitp
Copy link
Contributor

caitp commented Jun 20, 2014

I agree with Brian, on this one, fwiw, it's really a bizarre thing to do

@btford
Copy link
Contributor

btford commented Jun 20, 2014

Congrats, this example now lives here: 🎊 https://github.com/angular/angular-component-spec#bad-practices

@IgorMinar
Copy link
Contributor

this is invalid use of our apis. please create a module for your stuff rather than piggy-back on the ng module.

@ifyify
Copy link
Author

ifyify commented Jun 24, 2014

If mine subcontractors did that, anyone else can do it again.

You have great URL based error explanation: extend it to bad practices (for non production code base) attach to discussion thread and it will be really great.

It is the C style int32 problem, solve it and people will love you...

./F

On Jun 24, 2014, at 14:45, Igor Minar [email protected] wrote:

this is invalid use of our apis. please create a module for your stuff rather than piggy-back on the ng module.


Reply to this email directly or view it on GitHub.

@btford
Copy link
Contributor

btford commented Jun 26, 2014

Honestly, I don't think it even makes sense to document this more thoroughly.

  • The official Angular documentation shows how to correctly register filters.
  • The official Angular documentation rarely mentions the internal ng module. You have to go out of your way to find it. Nothing about the documentation or API suggests that modifying this module is a reasonable thing to do.
  • I explicitly added this to our list of poor practices for 3rd party components

There are so many more important things for us to work on.

@digish777
Copy link

What is the solution to this issue?

@gkalpak
Copy link
Member

gkalpak commented Oct 6, 2016

@digish777, this issue is about a very old Angular 1.x version (1.3.0.beta.8 specifically).
Are you sure you are having the same issue?

@digish777
Copy link

My office is trying to upgrade from 1.2.2 to 1.5. this filter is standing in the way. do not know how to fix this. that is why I asked.

@digish777
Copy link

http://plnkr.co/edit/txehajjSSoMV71at9Ygc?p=preview

This is exactly what is happening to me.

@digish777
Copy link

Uncaught Error: [$injector:modulerr] Failed to instantiate module ng due to:
Error: [$injector:unpr] Unknown provider: $filterProvider

@digish777
Copy link

I found the issue is happening at 1.3.0-beta.8. What got changed and how to fix it.?

@gkalpak
Copy link
Member

gkalpak commented Oct 7, 2016

The cause of the problem is explained in the comments above. In a nutshell, you should not be putting stuff on the ng module.

The proper way to solve this is to create your own module and add that as a dependency to your other modules. E.g.:

angular.
  module('utils', []).
  filter('tel', function() { ... });

angular.
  module('test', ['utils']).
  run(function(telFilter) {
    console.log(telFilter);
  });

The hacky, unrecommended, non-future-proof way to work around it is:

angular.
  module('ng').
  config(function($filterProvider) {
    $filterProvider.register('tel', function() { ... });
  });

@SudhaSusarita
Copy link

My case was,in my HTML file, I have declared ng-app="MyApplication" in two places.
While I removed that, the error was resolved.

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

Successfully merging a pull request may close this issue.

9 participants