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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -