Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binding ng-include src using $scope property

In angularjs app I want to dynamically load partial view, so I have in my view

<ng-include src="'{{ pathView }}'"></ng-include>

this view is ofcourse attached to certain controller and in my controller I have

 $scope.pathView= "/templates/listView.html";

this not work since when investigating html view I'm getting

<!-- ngInclude: undefined -->

When I hardcode template view path

<ng-include src="'/templates/listView.html'"></ng-include>

it works.

What I'm doing wrong?

like image 284
user1765862 Avatar asked Apr 29 '26 09:04

user1765862


2 Answers

src in ng-include needs a angular expression reference , so you can bind that to the model value as below

<ng-include src="pathView"></ng-include>
like image 70
Kalhan.Toress Avatar answered May 01 '26 00:05

Kalhan.Toress


Remove {{ and }}

Correct way <ng-include src="pathView"></ng-include>

like image 24
Arpit Srivastava Avatar answered Apr 30 '26 23:04

Arpit Srivastava