Hi Guys,
I cannot agree with you, Adam that AngularJS is little different than
jQuery as you are comparing oranges to apples. AngularJS uses jQuery
all the way under the hood and if one wants to do something which is
not directly provided by services and directives - it is very easy and
straight forward to do.
No need to hack angular, no need to walk around problems and no need
to break important rules of AngularJS. In my opinion this is the most
important feature of AngularJS - it does not step in our way :)
Few days ago, I had similar problem. The application shows OpenLayers'
map and I had to add a button to export a map as a bitmap in either:
another tab or as a browser's "save as..." dialog.
Quick browsing led me to the simple jQuery solution, here is how I
have applied it:
.directive('gisExport', function(dischargePoints, wmsLayers) {
return {
require: '^gisMap',
template: '<input type=button value="{{label}}"
ng-click="createAndSubmitForm()">',
scope: {label: '@gisExport'},
link: function(scope, elem, attrs, gisMapController) {
scope.createAndSubmitForm = function() {
var map = gisMapController.map,
bbox = map.getExtent().toBBOX(),
pixels = dischargePoints.asPixelString(map),
layers = wmsLayers.toString();
elem.append('<form action=gis-export target=_blank method=post>'
+ '<input type=hidden name=pixels value="' + pixels + '">'
+ '<input type=hidden name=bbox value="' + bbox + '">'
+ '<input type=hidden name=layers value="' + layers + '">'
+ '</form>');
elem.find('form').submit().remove();
}
}
}
})
This is simple jQuery solution I have found on the web, wrapped by
AngularJS infrastructure (directive) code. In markup I had to add a
button like this:
<div gis-map="map">
<div gis-export="Export as bitmap"></div>
<div id="map"></div>
</div>
As you can see, the "gisExport" directive is applied on a DIV element,
it communicates with a gisMap directive controller (do not confuse
directives' controllers with regular ones).
What is also important, such a code can be easily mocked in GUI tests
if one wants to exclude them in isolation. With little effort
(injecting bbox directly) it can be also easily unit tested (unit - I
mean in isolation).
Regards,
Witold Szczerba
P.S.
Adam, are you positive about your solution with $http? The $http
service is a XMLHttpRequest wrapper, so it is not going to post to
other domains, is it?
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to
ang...@googlegroups.com.
> To unsubscribe from this group, send email to
>
angular+u...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/angular?hl=en.
>
>