I'm working on attaching html elements with directives from another directive. I've managed to successfully append the html elements with directives using this answer.
But, the values added to these elements through the directives don't change with the scope change. For example,
Controller Code:
var DatepickerDemoCtrl = function ($scope) {
$scope.el=2;
};
Directive link function
link: function link(scope,element, attrs) {
element.attr('value', scope.el); //sets value to 2 as expected
element.removeAttr("common-things");
scope.el = 1 //Does not change value to 1
$compile(element)(scope);
//Even changing the scope variable after a timeout, the value remains 2
$timeout(function(){
scope.el = 4
}, 2000);
}
A working plunker can be found here: http://plnkr.co/edit/S1t2PlwTX2aUiYZR04pF?p=preview
Running $compile after changing the value works, but it resets all values in the element(ex-Changing an attribute and running compile removes the current ng-value).
How can I bind the values to the scope from inside the directive?