angularjs - using angular $compile for string replacement -
endpointtemplate = "/api/endpoint?city={{city}}&state={{state}}&facility={{facility}}"; var model = angular.extend(scope.$new(), { city: 'brooklyn', state: 'ny', facility: 'facility 2' }); var compiled = $compile($('<a>', { //none of these work expect 'ng-href': endpointtemplate, 'test': endpointtemplate, 'ng-bind': endpointtemplate })); var result = compiled(model);
i value out like:
"/api/endpoint?city=brooklyn&state=ny&facility=facility 2"
but angular doesnt seem leave string "as-is" (except ng-bind attempt, throws error)
how can make work?
you may notice result
became interpolated once digest cycle over. inappropriate use $compile
if that's required string interpolation, consider using $interpolate
instead, which
is used html $compile service data binding.
it should this:
var model = { city: 'brooklyn', state: 'ny', facility: 'facility 2' }; var result = $interpolate($('<a>', ...)[0].outerhtml)(model);
Comments
Post a Comment