Tuesday 15 April 2014

angularjs - Angular How to build a directive template when properties via web service are needed -



angularjs - Angular How to build a directive template when properties via web service are needed -

basically need build control, need details web service before can build html. proper way this.

here have @ moment, not sure if right or not, or whether should using controller, should webservice.get() method in link method of directive?

advice/input much appreciated

app.directive('mydirective', ['webservice', '$compile', function (webservice, $compile) { 'use strict'; homecoming { restrict: 'a', link: function (scope, element, attrs) { // info server webservice.get().then(function(columns) { var html = ''; // add together html here // .... // loop through server info (var = 0; < columns.length; i++) { html += '<td>' + columns.name + '</td>; } // build rest of html here // .... // compile html angular utilize html = $compile(html)(scope); // set element html element.html(html); }); } }; }]);

angularjs angularjs-directive

No comments:

Post a Comment