Tuesday, March 5, 2013

AngularJs and Xml Priming the Pump

AngularJS is powerful data binder.  It has MVC tools built in for basic tasks.  AngulaJS Directives, I wouldn’t say they are really part of the MVC.  They are powerful!
When using directives against xml, there is a chicken and an egg problem. Angular does a good job separating code from data.  But sometimes they are the same.  Think dynamic sql, (which I agree is bad).  Putting raw xml on the page and then applying directives requires a different approach than the traditional MVC.
The code below will put the raw xml on the page.  In the xml, each element must have a namespace prefix. The root must have the namespace uri. 
Then other directives can be applied to the xml.

Directive
MyApp.directive('loadXmlGetById', function (MySvcApi) {
    return {
        priority: 500,
        templateUrl: MySvcApi.getByIdUrl,
    };
});
Html
<div load-xml-get-by-id></div>
MySvcApi
Is not much of a service, just a function that returns a string with the url for my services + the Id which it gets from the ($location.Search()).Id

No comments:

Post a Comment