I am looking to dynamically compile a component and insert it into a specific DOM element, which is also dynamically created by a third-party library. To achieve this, I am utilizing the $compile
and $scope
.
https://jsbin.com/gutekat/edit?html,js,console,output
// ListController $postLink life cycle hook
function $postLink() {
...
$timeout(function () {
ctrl.items.splice(0, 1);
$log.debug('First item of array is removed');
$log.debug(ctrl.items);
}, 2000);
}
However, the $onChanges
life cycle hook in the ListItemController
is not being executed.
// ListItemController $onChanges life cycle hook
function $onChanges(changes) {
if (!changes.item.isFirstChange()) {
$log.debug(changes); // Not executed
}
}
I suspect that using angular.merge
to pass the item
before initializing the ListItemController
controller instance is causing this issue.
var itemScope = $scope.$new(true, $scope);
itemScope = angular.merge(itemScope, {
$ctrl: {
item: item
}
});