Why ngModel doesnt set the initial value from the Controller?
Example: http://plnkr.co/edit/sGFv4zpVtvpsmUx1c9F3
angular.module('customControl', [])
.directive('contenteditable', function() {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelController
link: function(scope, element, attrs, ngModel) {
if(!ngModel) return; // do nothing if no ng-model
// Specify how UI should be updated
ngModel.$render = function() {
element.html(ngModel.$viewValue || '');
};
}
};
});
function TestCtrl($scope) {
$scope.userContent = 'It Works!!!!';
}
You gave the module the name "customController", so you have to give the ng-app a name as well.
Change <html ng-app>
to
<html ng-app="customControl">
and it should fix your problems.
Working example: http://plnkr.co/edit/bVYavNKuwV9BjrDNz2Hm