I have a situation where I need to fix an event when the model changes, but initialization in my directive fires the event too early.
Plunker: http://plnkr.co/edit/2T0Rq6yOXHWxQAOv8RpX?p=preview
How can I overcome this? Setting some flags, but how / where? Other approaches?
Thanks!
UPDATE
I added an attribute valueto the directive so that you can better understand what I mean by initialization.
value
Plunker: http://plnkr.co/edit/a5fzJi7VzAytj3Urj06L?p=preview
I finally decided it!
form Angular $dirty. false, , ngModel "". ngModel , form.
form
$dirty
ngModel
PS. , , .
data
$scope.data = { x: 51 }
Angular , : y z, undefined. 0 . ,
y
z
0
{ x: 51, y: 0, z: 0 }
, $scope.data , . .
$scope.data
, data y z:
$scope.data = { x: 51, y: 0, z: 0 };
You can check if a property exists for an object. demo
if ((newValue !== oldValue) && oldValue.x) {
or perhaps a more accurate demonstration :
if ((newValue !== oldValue) && (typeof oldValue.x !== 'undefined')) {
Source: https://habr.com/ru/post/1525068/More articles:Inverting linked list in python - pythonPython - Transpose List of lists of various lengths - 3.3 easiest method - pythonDebugging in Rails? - ruby | fooobar.comКак отрегулировать диапазон сюжетов оси Y в Matlab? - matlabHTML text aligns strangely - htmlSlick TextField not working - javafstream removes N bytes from the end of a binary file - c ++Search the Oxford Dictionary - javaHow to get the angular value of a perspective camera in Three.js? - javascriptWhat is the most efficient way to access a field value in an ADO recordset? - vb6All Articles