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

Add example on how to use the injector from outside Angular #5188

Closed
wants to merge 1 commit into from

Conversation

joscha
Copy link
Contributor

@joscha joscha commented Nov 28, 2013

Sometimes you integrate Angular in an application that has been there for a while and not all parts of the app are written in Angular. If you need to dynamically add Controllers to that project from outside Angular (let's say jQuery) then this example is for you.

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

…Angular

Sometimes you integrate Angular in an application that has been there for a while and not all parts of the app are written in Angular. If you need to dynamically add Controllers to that project from outside Angular (let's say jQuery) then this example is for you.

No breaking changes
@joscha
Copy link
Contributor Author

joscha commented Nov 29, 2013

Joscha Feth

@petebacondarwin
Copy link
Contributor

Hi @joscha - thanks for this example. While the method you suggest certainly allows you to compile up new HTML on a page from outside an Angular app, I am not sure this is the best method.

If you have an app that has no angular in it already then how are you adding angular in the first place? You could add in the angular markup before you bootstrap the app.

I am doing something similar in my github chrome extension, where I really don't have access to the HTML beforehand! See https://github.com/petebacondarwin/github-pr-helper/blob/master/src/githubHacks.js

If you are talking about adding new controllers in at a later stage then this could probably be done from within Angular too.

Perhaps you could provide some more info about your specific case?

@joscha
Copy link
Contributor Author

joscha commented Dec 5, 2013

Hi @petebacondarwin - our application is a huge legacy application based on jQuery mostly. We have our own (very old) legacy controller pattern that injects content into an iframe after page load. The only callback we have is within that legacy controller, so that's were we need to bootstrap any angular controllers that might have been loaded. The only other place that has angular at that point is the main app which got automatically bootstrapped on the document containing the iframe. I suppose I could access this application from within the callback - does that make you think of a better alternative of angularifying the new iframe content?

@petebacondarwin
Copy link
Contributor

I see so you have legacy code injecting DOM elements that contain angular markup inside an angular-app. Fair enough.

@joscha
Copy link
Contributor Author

joscha commented Dec 5, 2013

@petebacondarwin exactly, and the code I proposed for the docs is working like a charm exactly for that... do you know what I need to do to make @mary-poppins re-check my CLA status and the commit message?

@petebacondarwin
Copy link
Contributor

Don't worry about Mary. She doesn't actually know anything about CLAs yet as they are not accessible outside of Google.

@petebacondarwin
Copy link
Contributor

Merged with tweaks. Thanks

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this pull request Jan 27, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants