javascript - AngularJS Directive Not Evaluating Object Properly -
i'm using objects improperly somehow. basically, want:
angular.module('mobiledashboardapp') .directive('localforagemodel', function ($localforage) { return { link: function postlink(scope, element, attrs) { scope.$watch(attrs.ngmodel, function () { $localforage.setitem(attrs.localforagemodel, scope[attrs.ngmodel]); console.log(attrs.ngmodel); console.log(scope[attrs.ngmodel]); console.log(scope.user.companyid); console.log(scope["user.companyid"]); }); } }; });
to output
user.companyid dsf dsf dsf
instead of current output is:
user.companyid undefined dsf undefined
can point me in right direction? or suggest better title this?
you have incorrect notation, must be
var props = attrs.ngmodel.split("."); scope[props[0]][props[1]]
as dot notations not valid dynamic properties, object['abc.def']
must written object['abc']['def']
side-note, should have kind of object property checkings, example, if ngmodel attribute not abc.def
- throw exception, better have generic function this
Comments
Post a Comment