if scope model undefined var removeWatch scope watch model function ne

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if (scope.model === undefined) {
var removeWatch = scope.$watch('model', function(newValue, oldValue) {
if (newValue === oldValue) return; // skip initialization
scope.contacts = Contacts.query({company: scope.model.billing_organization});
scope.calcPriceAndTotal();
removeWatch();
});
}
if (scope.model === undefined) {
// we're in the edit dialog. $watch for model to become defined so we can calculate the total.
var removeWatch = scope.$watch('model', function(newValue, oldValue) {
if (newValue === oldValue) return; // skip initialization
scope.contacts = Contacts.query({company: scope.model.billing_organization});
scope.calcPriceAndTotal();
removeWatch();
});
}