Thanks Kamal. I didn't test my answer just was trying to point him the right direction. That makes sense.
On Sun, Mar 9, 2014 at 10:39 PM, Kamal <[email protected]> wrote: > Luke, > An small update on the code, the angular.element should be used for > `temp.chldNodes[11]` as html is an jqLite/JQuery methods which is returned > by angular.element. As the TypeError also states undefined is not a > function which would be `*.html` *in this case. And also childNodes would > have all the nodes which are HTMLElement or not (comment, text, etc..). > > $scope.modif = function (e) { >> var temp = e.target.offsetParent.offsetParent.childNodes[3].childNodes[( >> this.$index+1)*2]; >> angular.element(temp.childNodes[11]).html($compile('<button >> ng-click="save($event)">Save</button>')($scope)); >> }; > > > > On Monday, 10 March 2014 01:22:17 UTC+5:30, Luke Kende wrote: >> >> You are mixing angular scope with dom manipulation. They are two >> different things so not surprised you are having trouble. $scope values >> should point to javascript literals, objects, arrays, but not to dom >> elements. You can't call a jquery method without wrapping it first.... Try >> this: >> >> $scope.modif = function (e) { >> var temp = >> angular.element(e.target.offsetParent.offsetParent.childNodes[3].childNodes[(this.$index+1)*2]); >> temp.childNodes[11].html($compile('<button >> ng-click="save($event)">Save</button>')($scope));}; >> >> >> On Sunday, March 9, 2014 9:48:20 AM UTC-6, François S wrote: >>> >>> I have un little problem with DOM manipulation. >>> >>> Here's my angular function: >>> >>> $scope.modif = function (e) { >>> $scope.temp = >>> e.target.offsetParent.offsetParent.childNodes[3].childNodes[(this.$index+1)*2]; >>> $scope.temp.childNodes[11].innerHTML = $compile('<button >>> ng-click="save($event)">Save</button>')($scope);}; >>> >>> but my button is rendered like that in the document: >>> >>> [[object HTMLButtonElement] >>> >>> I know that using innerHTML with Angular is wrong but when i'm using >>> .html() i have this error: >>> >>> $scope.modif = function (e) { >>> $scope.temp = >>> e.target.offsetParent.offsetParent.childNodes[3].childNodes[(this.$index+1)*2]; >>> $scope.temp.childNodes[11].html($compile('<button >>> ng-click="save($event)">Save</button>')($scope));}; >>> >>> TypeError: undefined is not a function at h.$scope.modif >>> >>> Thanks, >>> >>> François >>> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "AngularJS" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/angular/DxElKMDIXpo/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
