user1961008 user1961008 - 22 days ago 16
AngularJS Question

ng-include loading partial partial only once

Ng-include is driving me nuts and I really hope you can help.
So I have this html code on the master page

<div id="subViewPartial">
<ng-include class="col-md-8 col-md-offset-2" src="currentPartial">
</ng-include>
</div>


and in angularjs I have the following functions

$scope.createUnit = function (link) {
$rootScope.Action = 0;
$rootScope.Id = 0;

$scope.currentPartial = window.location.origin + link;
setTimeout(SubViewService.showSubView(), 500);
};

$scope.createUser = function (link) {
//////console.log(link);
$scope.currentPartial = window.location.origin + link;
setTimeout(SubViewService.showSubView(), 500);
};


Now, if fire createUser once, and then I execute createUnit serveral times, the subview will rotate between createUser and createUnit even though I am not calling createUser.

Here is the SubviewService as well

BAapp.service('SubViewService', function () {
this.showSubView = function () {
var subViewContent = '#subViewPartial';

$.subview({
content: subViewContent,
onShow: function () {
},
onClose: function () {
$.hideSubview();
},
onHide: function () {
}
});
}


});

I hope that I am clear in explaining the problem. Any idea what is going on?

Answer

What you should do is take a good look at where the createUnit() and createUser() functions are called. For instance by setting console.debug() statements or a debugger statement in those methods.

You mention they are part of separate controllers, does this mean the functions are called during initialization of said controllers?

If this is the case, you are probably (accidentally) creating the controller that calls createUser() more than you think, possibly because of ng-include, ng-if or ng-switch constructions.

Comments