div模擬輸入框 數(shù)據(jù)是如何同步的
angular.module("FormModule",[]).directive("contenteditable",function(){
return{
require:'ngModel',//ngModel大寫
link:function(scope,elm,attrs,ctrl){
//view->model
elm.bind("keyup",function(){
scope.$apply(function(){
ctrl.$setViewValue(elm.text());
});
});
//model->view
ctrl.$render=function(){
elm.html(ctrl.$viewValue);
};
//load?init?value?from?DOM
ctrl.$setViewValue(elm.html())
}
}
})
2016-11-13
view -> model通過$setViewValue,
model -> view通過elm.html(ctrl.$viewValue)。