मेरे पास निम्नलिखित ckEditor निर्देश हैं। नीचे दो बदलाव हैं जो मैंने उदाहरण से देखे हैं कि संपादक में डेटा कैसे सेट करें:
app.directive('ckEditor', [function () {
return {
require: '?ngModel',
link: function ($scope, elm, attr, ngModel) {
var ck = null;
var config = attr.editorSize;
if (config == 'wide') {
ck = CKEDITOR.replace(elm[0], { customConfig: 'config-wide.js' });
} else {
ck = CKEDITOR.replace(elm[0], { customConfig: 'config-narrow.js' });
}
function updateModel() {
$scope.$apply(function () {
ngModel.$setViewValue(ck.getData());
});
}
$scope.$on('modalObjectSet', function (e, modalData) {
// force a call to render
ngModel.$render();
});
ck.on('change', updateModel);
ck.on('mode', updateModel);
ck.on('key', updateModel);
ck.on('dataReady', updateModel);
ck.on('instanceReady', function () {
ngModel.$render();
});
ck.on('insertElement', function () {
setTimeout(function () {
$scope.$apply(function () {
ngModel.$setViewValue(ck.getData());
});
}, 1000);
});
ngModel.$render = function (value) {
ck.setData(ngModel.$modelValue);
};
ngModel.$render = function (value) {
ck.setData(ngModel.$viewValue);
};
}
};
}])
क्या कोई मुझे बता सकता है कि क्या अंतर है:
ck.setData(ngModel.$modelValue);
ck.setData(ngModel.$viewValue);
और जो मुझे उपयोग करना चाहिए। मैंने कोणीय दस्तावेज को देखा और यह कहता है:
$viewValue
Actual string value in the view.
$modelValue
The value in the model, that the control is bound to.
मुझे पता नहीं है कि जब लेखक ने दस्तावेज़ में यह लिखा था तो उसका क्या मतलब था :-(
$viewValueहमेशा एक स्ट्रिंग है?