Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-include with a variable for src

I would like to change the ng-includes src with a variable. Currently this is what I have.

 <div class='alignRightCenter' id='rightContent'>     <ng-include src="'{{view}}'"> </ng-include> </div> 

And here is the controller:

ctrl.controller('contentCtrl', ['$scope', function($scope) {       $scope.view = "partials/setListName.tpl.html";   }]); 

Unfortunately I can not use a ng-view because it is already being used to get me to this page. Is it possible to make something like this work?

like image 352
Austin Lovell Avatar asked Feb 18 '14 16:02

Austin Lovell


2 Answers

Try as follows:

<ng-include src="view"> </ng-include> 

-----------------OR----------------------

You can do this way,

View:

<div data-ng-include data-ng-src="getPartial()"></div> 

Controller:

function AppCtrl ($scope) {   $scope.getPartial = function () {       return 'partials/issues.html';   } } 
like image 69
Jatin patil Avatar answered Sep 22 '22 17:09

Jatin patil


Like this. You need to use single quotes and +, like you would in JavaScript.

<ng-include src="'/path/to/template'+ my.variable +'.html'"></ng-include> 
like image 26
JRT Avatar answered Sep 22 '22 17:09

JRT