为什么 ngModel 没有从 Controller 设置初始值?
示例: 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!!!!';
}