javascript - Angular - Set up a path variable that changes per page -
i ng-including partials in different portions of site, @ different folder levels. because of that, need able set, per page, root relative folder path assets such partials , images can found. example, this, correctly:
index.html:
<div class="homepage"> <ng-include src="'patterns/header.html'"> </div>
but able access same partial below:
/individuals/header/index.html
<div class="individual"> <ng-include src="'../../patterns/header.html'"> </div>
is there method setting like
pathis = '../../patterns/'
that used on individual page so:
<ng-include="{{pathis}} + 'header.html'">
and if so, that? directory structure below:
index.html | patterns/ --------header.html | individuals/ --------header/ ----------------index.html
(i including header.html in both index.html in individuals/header/index.html)
there many ways that, 1 way storing relative path in service, such example:
services.factory('configurationservice', function(){ var root = {}; root.getwebappcontextname = function () { return "/myapp"; }; return root; });
in controlller:
$scope.gettemplatepath = function () { return configurationservice.getwebappcontextname() + "/myspecificpath/; } $scope.templatepath = $scope.gettemplatepath();
in html:
<div id="header" data-ng-include data-src="templatepath + 'header.html'"></div>
Comments
Post a Comment