Reputation: 263
How can I access an embedded resource (.html) from an AngularJS javascript controller that expects a URL path to the html?
Some background: I have a .NET MVC site, several portable areas (using MvcContrib) in different projects that produce a .DLL with embedded controllers, views, css, js & html. These DLLs are then referenced in the main .NET MVC site.
One of the Portable Areas uses AngularJS, previously it was a full .NET MVC project using MEF(Microsoft Extensibility Framework) however I am moving to a portable area and doing away with MEF.
Portable Areas are all working fine, my main MVC app is hitting the controllers and views as expected,CSS and JS files embedded in the Assembly are getting accessed.
Now the challenge is with AngularJS, getting the embedded resource from c# .net on the server side is fine but when angular looks for a path to a file in javascript that is now embedded how can it be handled.
An example
$scope.editObject = function () {
var modalEditObject = $modal.open({
templateUrl: $rootScope.applicationFolder + '/views/editObject.html',
controller: 'CRUDObjectController',
windowClass: 'popup',
size: 'lg',
resolve: {
object: function () {
return $scope.gridApi.selection.getSelectedRows()[0];
}
}
});
.....
In the example above, this line is looking for the corresponding HTML file to use. However this is now an embedded resource in the Assembly.
templateUrl: $rootScope.applicationFolder + '/views/editObject.html'
Upvotes: 0
Views: 489
Reputation: 940
you can use a function on templateUrl that provides the url path:
like so
templateUrl:myFunc,
$scope.myFunc = function() { return $rootScope.applicationFolder + '/views/editObject.html'}
Upvotes: 0