I have the following code:
angular
.module('myApp')
.directive('layout', function () {
return {
restrict: 'E',
template: '<div ng-include="layoutCtrl.pageLayout"></div>',
controller: 'LayoutController',
controllerAs: 'layoutCtrl',
bindToController: true,
scope: {
pageLayout: '=',
pageConfiguration: '=',
isPreview: '='
}
};
});
angular
.module('myApp')
.controller('LayoutController', LayoutController);
function LayoutController($scope, LayoutDTO, LayoutPreviewDTO) {
var self = this;
self.layoutDTO = LayoutDTO;
self.layoutPreviewDTO = LayoutPreviewDTO;
var test = $scope;
if(self.isPreview)
self.layoutModel = new self.layoutPreviewDTO(self.pageConfiguration);
else
self.layoutModel = new self.layoutDTO(self.pageConfiguration);
}
<div>
<layout page-layout="ctrl.layoutTemplateUrl" page-configuration="ctrl.pageConfiguration" is-preview="false"></layout>
</div>
In the angular 1.5.3 version this worked as expected, the variables in my Controller were coming in with values. Now, since I upgraded to 1.6.x, self.pageConfiguration is now undefined.
Nothing has changed except for the angular version.
How do I get a handle on the values passed into the directive in my controller?
I figured it out:
https://github.com/angular/angular.js/commit/dfb8cf6402678206132e5bc603764d21e0f986ef
This defaults to false now, must set to true $compileProvider.preAssignBindingsEnabled(true);
The AngularJS team recommends that controller code that depends on scope bindings be moved into an
$onInit
function.UPDATE
The
$compileProvider.preAssignBindingsEnabled
flag has been removed from AngularJS V1.7.The AngularJS team strongly recommends migrating your applications to not rely on it as soon as possible. AngularJS V1.6 goes end-of-life on 1July2018.
From the Docs:
Note:
On 1July2018, support for AngularJS 1.6 ends. For more information, see AngularJS MISC - Version Support Status.