Question

I'm trying to catch each "noscript" tag in my view. I create a function in my factory, and call it when the controller is launched.

Here's my function :

angular.forEach(angular.element(document.querySelector('noscript')), function (value, key) {
// some code

The problem is that the "noscript" elements are in a ng-include, and it seems that the include is launched after the controller .. Then, I can't catch the elements !

What is the best way to do that ? Thanks by advance :)

Was it helpful?

Solution

You could write a directive that exposes a function for handling noscript tags within an include. You could call the function via the onload attribute of the ng-include.

Fiddle: http://jsfiddle.net/REYhN/

Please note, that you should avoid doing DOM manipulation in controllers. That's what directives are for: http://docs.angularjs.org/api/ng/service/$compile

OTHER TIPS

Get it !

I called my controllers in my routes.. I read somewhere that it isn't a good practice. Understand why now.

The solution is to call your controller in the partial via ng-controller. And then, you can do whatever you want and get every dom elements :).

Not sure why you want to catch the noscript tags, but have you considered using modernizr instead of noscript tags?

w3c noscript

The noscript element is a blunt instrument. Sometimes, scripts might be enabled, but for some reason the page's script might fail. For this reason, it's generally better to avoid using noscript, and to instead design the script to change the page from being a scriptless page to a scripted page on the fly...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top