Welcome! I have some code here that I'm working on. The goal is to allow users to create multiple divs whose properties are bound to the controller's model.
appModule.controller('textController', function($scope){
var box = {x: '0', y: '0', height: '100px', width: '200px', text: 'this is the default text'};
$scope.textBoxes = [box];
$scope.addNewTextBox = function(){
console.log("creating new textbox!!!");
$scope.textBoxes.push(box);
};
});
appModule.directive('tbox', function($document){
return {
restrict: "E",
template: '<div><div ng-transclude></div>',
transclude: true,
scope: {
model: "=",
},
link: function postLink(scope, element, attrs, ctrl){ //the scope here is the object's scope
var length = scope.$parent.textBoxes.length;
console.log(length);
scope.model = scope.$parent.textBoxes[length-1];
}
}
});
I've encountered an issue where I can't assign the model variable in the scope to the textBoxes variable in the controller. This results in the following error:
Error: Non-assignable model expression: undefined (directive: tbox)
at Error (<anonymous>)
at h (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:43:213)
at Object.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:43:326)
at Object.e.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:87:13)
at Object.e.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:89:198)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js:16:239
at Object.d [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.
Any thoughts on what might be causing this?