how to add external models angularjs - javascript

Reminder I am new to angular ways.. I would like to use an external model like bindeonce in my project but it the readme says "Include the bindonce.js script provided by this component into your app." Does it mean I should add the file to the folder or just add the script using the html tags and call the min.
Thanks

Related

ember vendor js file does not seem to be working

I am trying to work an admin theme into an ember project. There is a custom.js file that has a lot of the javascript for the sidebar, header stuff etc. I have it in the vendor folder vendor/custom.js. I am including it in ember-cli-build as app.import('vendor/custom.js'); When I look in chrome at the vendor.js file I see the contents listed in it, but the javascript on the page does not work.
If I take some of the sections out of the custom.js and put them in the hbs file within tags the do run and work. I'm wondering why just including importing the file doesn't work.
Any thoughts on what could be wrong?
Here is a link to the custom.js file Custom.js Gist
You are trying to include customjs from the admin theme into your app.
Instead of including the custom.js directly, create custom components for each admin-theme component.
In your component you can register you click-event handler and you jquery custom code. There is a old blog post from a core team member acout this.
http://www.programwitherik.com/how-to-initialize-a-jquery-component-with-ember-js/
But i think you need some basic knowledge about how ember is rendering and what a component is compared to a controller + template. You also need to understand what the admintheme js is trying to achieve.

How do i render a html file in grails that has source files included in the html?

I have a project in grails where I'm doing the UI part in a separate grails independent project. I'm calling the html file in the UI project from the grails controller in a different project.
How do I render the html files from the controller? Currently, I'm using the render command to convert the htmlContent into text format and rendering the text. But I released I cant include relative source tags inside that html and I'll need to hardcode it in the html.
render text: htmlContent, contentType:"text/html", encoding:"UTF-8"
Any other effective way to render the html (from a different project) from the grails controller?
The following is the problem as I understand it:
You have a Grails project containing a controller.
You have Grails plugin project containing the UI (html, css, etc).
The controller project is configured in grails-app/conf/Build.groovy to depend on the UI plugin.
You want to render the UI in the UI plugin project from the controller in the controller project.
Views are rendered exactly the same way regardless of whether they are contained in the same project or not. For example, if the UI project has a view at grails-app/views/ui/index.gsp, then the controller in the controller project can render it like this:
render(view: '/ui/index')
I don't know where your htmlContent is coming from, but usually rendering text is for very simple things, such as JSON; not for HTML which may contain other resources (like images and CSS files).
See, in Grails the URLs to static resources, such as images and CSS files, are generated by either the Resources or Asset-Pipeline plugins. Either way, trying to set the path to such resources directly in HTML code will not work.
If you convert you htmlContent into a GSP page and use either the Resources or Asset-Pipeline, then you'll be able to render HTML content with sources.
Check grails-app/conf/Build.groovy for the line compile ":asset-pipeline:x.x.x" in the plugins section. If it's there, heck just go with the Asset-Pipeline! It's the new way to manage static resources.

Reference to ejs view files does not change after the build, although it combines it inside of production.js - Javascript MVC

In the code we use something like this:
$('#wrapper').html('//app/views/content.ejs', {foo:"bar"});
And when we build the app, this still stays the same, although the content.ejs file is built into production.js.
So my question is, what should we do so that when we build the app, these references point to ejs files inside of production.js?
We are using JMVC 3.2.2
We've also tried using this way:
$('#wrapper').html( $.View('//app/views/content.ejs', {foo:"bar"}) );
Your views are not getting added to production.js; you need to steal each one of them:
steal('//app/views/content.ejs');
JMVC 3.1:
steal.views('//app/views/content.ejs');
Got the answer in JMVC forum: https://forum.javascriptmvc.com/topic/#Topic/32525000000958049
Credit to: Curtis Cummings
Answer:
The paths to the views do not need to change.
When the production.js file is created, your views are included and
get preloaded when the script runs. When you reference:
'//app/views/content.ejs', view first checks if the view file you are
requesting has been preloaded and if it has, will use that instead of
making a request for the .ejs file.

Dynamically creating javascript file in Rails 3.1

I am attempting to create a plug and play shopping cart in Rails 3.1 that allows users to add a shopping cart to their site by just adding a link to a javascript file. The items for sale are input on my end and stored in this js file and rendered with jquery templates. I currently have an action that renders the corresponding js, but I was wondering if there was a way to create a new minified js file for each site and link to this file in each site instead of the show action that renders the js.
For example, for store#1, I would like to create and save a js file called store1.js and serve that file instead of calling the show.js action that creates the javascipt array for the jquery templates every time.
You could try using action caching to have it only render the action once. Then you can utilize cache sweepers to invalidate the cached js when you make any updates that would change the information in the js.
I think that really might be your best option. Your going to go through a lot more trouble trying to get precompiled dynamic JS like that, especially if the content has a tendency to change at all.

How to access proprietary .js file in Spring MVC?

I am newby in Spring, but have a task, and I am learning on the fly.
I used Roo to generates for me part of the code, but now I have to make some dynamic list binding, which is done with form, popping-up in new window, and when the submit button is pushed I have to insert the new values in the parent window.
For the purpose I wrote a .js file, which hooks the values to the parent DOM tree, but the point is that I can't configure Spring to deliver the required .js file to the browser.
The browser, doesn't recognize my function. Even when I try to access the .js file via the browser, I receive error that the file couldn't not be found.
I've tried to configure the web.xml, but it didn't work...
Any ideas, how I can configure the access to a .js file in a Spring MVC application?
Thanks a lot!
P.S. Respectively, I'll need to grant access for a static .htm(l) file... I suppose the principle for configuration of the access of static html files is the same..., right?
You just need to get the path to the file right. Assuming you have a Maven-like set-up (I assume you do because you're using Roo), then your script belongs under src/main/webapp - probably in something like a scripts folder.
Let's assume that your file is at src/main/webapp/scripts/myscript.js
You can create a URL reference for your script by adding the following Spring tag:
<spring:url value="/scripts/myscript.js" var="script_url"/>
This should give you the right path to your script, regardless of the context in which you later decide to publish your webapp.
After that, it's just a matter of using that reference:
<script type="text/javascript" src="${script_url}"></script>

Categories