changing ng-include dynamically

3.8k views Asked by At

I am very new to Angular. I'm trying to dynamically change the value of ng-include in my header whenever the user selects a "facebook page". I cannot figure out why what I have is not working. I have tried everything I have found in stackoverflow and I stopped with these instructions: http://blog.dynamicprogrammer.com/2012/09/19/dynamic-includes-with-angular-js.html

This is my html:

<!-- BEGIN HEADER -->
<div data-ng-include data-ng-src="getPartial()" data-ng-controller="HeaderController"
         class="page-header navbar navbar-fixed-top">
</div>
<!-- END HEADER -->

This is my controller:

* Setup Layout Part - Header */
PicoApp.controller('HeaderController', ['$scope', function ($scope) {
    $scope.$on('$includeContentLoaded', function () {
        Layout.initHeader(); // init header
    });

    $scope.getPartial = function () {

        if (!FacebookPage.currentPage) {
            location.href = "#/";
            return 'tpl/header.html';
        } else {
            location.href = "#/";
            return 'tpl/header_main_page.html';
        }   
      }

}]);
1

There are 1 answers

0
Rajkumar Rathi On BEST ANSWER

In the div statement the function is added to ng-src which is not needed. Update the code to this

<div data-ng-include="getPartial()" data-ng-controller="HeaderController"
         class="page-header navbar navbar-fixed-top">
</div>