Groovy code not accessible inside AngularJs component - angularjs

I have some groovy code inside my AngularJs 1.5 component's template. As you might know,the component template property does not allow us to add any file except HTML file(or does it?),whereas the groovy code will not execute inside a HTML file. Is there any way to do this?
FYI, I have already tried using component transclusion but it does not serve the purpose well as it creates numerous child scopes(as I need multi-slot transclusion). When I need to access my controller(which I need to do very often) from inside the transcluded element the only possible way I came across was using the required numbers of $parent, which does not look great at all.

whereas the groovy code will not execute inside a HTML file. Is there
any way to do this?
Not really, no. In theory it could be done, but someone would have to build a technology to support that.

Related

Compile HTML string in AngularJS

So, a little background on this, I have an AngularJS/Ionic project that I'm attempting to do some improvement on, I'm placing all my HTML/JS/CSS into a database table, which in turn will be retrieved on a GET upon app start. HTML is then saved in a factory(also local storage). The goal, is to have an app that can be controlled from the HTML/JS/CSS that is within the Database table, so that we don't need to redeploy new versions for simple updates/fixes. Here's what I have tried:
The most successful method I used was using the below within the controller:
$scope.pageContent = $sce.trustAsHtml(htmlString)
and calling it within the HTML like below:
<div ng-bind-html="pagecontent"></div>
The only problem is, that it isn't compiling correct in a few ways - All my $scope values within the HTML aren't being linked to the parent controller scope.
My questions is: Is there a better way of handling this? I've seen a few people claiming using directives would be the way to go, but can't get a definitive answer on how to implement. Or, is how I'm moving forward working, and I'm just missing some key components... Any help on best way to implement would be greatly appreciated. Let me know if I left any information out, thanks!

Possible to use Camel's XSLT component with dynamic templates?

By dynamic templates, I don't mean a dynamic URI. I mean the template itself which is assembled from pieces sitting in a database, transformed in various ways, has images inserted into it, etc. All this is done within my Camel Routes. The finished XSLT template is sitting in an exchange property and now I want to run the message body XML through that XSLT.
Unlike the XQuery component which provides a lot of flexibility, it seems that the template file must come from only an external source with the XSLT component. Am I forced to write it out as a file first?
Set the option contentCache=false then the template is re-read on each message. Then it can load eg from a file, where you can then update the file with new content as you want.
To add support for using bean or ref as the resource, so you can call a bean etc, is currently not supported but I logged a ticket so we will add that in a future release: https://issues.apache.org/jira/browse/CAMEL-11514

How to manage scripts for each view in Angularjs ui-router?

I'm using ui-router/stateProvider to load various views for a single page app. Additionally I'm following what appears to be best practice for structuring code by breaking my code into components so I have, for example;
Index.html
\Components
\Component1
\page1.html
\page1.css
\page1-controllers.js
\page1-directives.js
\Component2
\page2.html
\page2.css
\page2-controllers.js
\page2-directives.js
I have quite a few different views/components (10+) and my question really relates to how to manage the loading of the js files (and the CSS files for that matter). I can put the JS files all in tags in the index.html file and all works fine, but looks a bit messy as it is a very long list.
So my question is: How should I manage the inclusion of the various scripts for each view; should they all remain in the index.html file or is there a better way of managing them, such as loading only when each view is called via the ui-router?
Many Thanks
I think that you need to use RequireJs, I will include a couple of sites with the documentation that explain how implement that.
http://www.javascripthtml.com/load-dynamically-javascript-file-in-angularjs-with-requirejs/
https://cdnjs.com/libraries/backbone.js/tutorials/organizing-backbone-using-modules
For css you may want to add a single class to each view then use a single css file for all views. I keep the css organized into modules for easy access. This will also help load times as it will require less requests.
For js I would create a universal js file that contains any code that is required for ALL views, then create individual js files for individual views. There really isn't a "right" way per se but preferred ways depending on the developers you work with. Keep it simple and easy for other developers to read. :)
I have the same problem as you, I think that the only solution for us is to add the script in the "index.hmtl" page.

AngularJS constructor or init?

All,
We are developing our app with AngularJS and time and again we keep running into the issue of Angular running or loading controllers twice. This becomes a little more intrusive when testing our controllers and more specifically when working with Testacular with jasmine's SpyOn's (since they get triggered before our code runs). So, our question is, is there such a thing as a constructor or init method that Angular is guaranteed to call when instantiating the controllers w/o having to hack work-arounds in the test code? TIA.
If you are specifying the controller in your router, then your template doesn't need to specify the controller via an ng-controller tag. Doing so will double load your controller.
Your controllers shouldn't be loaded twice, unless you are doing something wrong. You shouldn't have to hack any work-arounds.
You might want to provide a concrete example of how you are loading the controllers (and/or the partials which are associated with the controllers). It sounds like you probably have a routing issue which is causing your view to be loaded twice for each request.
Assuming that is a routing-related issue, unless/until you can provide more information to help people to help you, you may want to read this document. Pay particular mention to sections that mention 'redirect' and 'HTML 5' mode:
http://docs.angularjs.org/guide/dev_guide.services.$location
With so little information to go on, I can't answer your question, but perhaps that link will help you to help yourself. :)

CakePhp - how does it combine files for result

I've seen the diagrams, but I want a description of how it all works -- for example -- cakephp uses the controller file and the view file. What happens? Is there anything out there? It would make using cakephp's mvc easier.
most simple request would look something like the following:
when you request a url, the router figures out what is needed and then uses the Dispatcher to open up the controller and run the corresponding method.
As the controller is fired up it includes and builds up the model that corresponds to that controller.
your method will then run and do what ever it needs to do.
When the controller is done calling all the code you have included the view class is executed which starts the rendering. It will include and render the corresponding view file and then the layout that has been set in the code.
all along the way there are a number of callbacks that are triggered in the various parts of the code, like controller::beforeFilter model::afterFind etc. Best to have a look a the api and book for more detailed information or ask a more specific question about that.
If you're at all familiar with Object Oriented code and php functions, you can start to read the CakePHP core methods. They will fill in a lot of blanks in terms of understanding the internal mechanics and relationships of Models Controllers and Views.

Resources