How to reapply directive when scope is changed in AngularJS

914 views
Skip to first unread message

Jason Villalon

unread,
Jun 3, 2014, 7:58:22 PM6/3/14
to ang...@googlegroups.com
Im trying to refresh my jquery plugin after the data is changed.


its seems that after changing the scope, jquery plugin is not beeing re-initialized.

Thanks in advance.

Sander Elias

unread,
Jun 4, 2014, 1:42:44 AM6/4/14
to ang...@googlegroups.com

Hi Jason,

Your sample works fine, even without the $rootScope.$broadcast('test');.
However, it will not update if you change something at a deeper level in your menu.
There is a third parameter to $watch that you can set to true, if you do so, it will work.

Play with this, and lookup the documentation of $watch, and while you are on it, also look up $watchCollection

Regards
Sander

Jason Villalon

unread,
Jun 4, 2014, 2:31:21 AM6/4/14
to ang...@googlegroups.com
Hi Sander,

Thank you for your reply. I removed the broadcast in my code and added true to the third parameter in $watch method. but still doesnt work. is it working on your end?

here is my updated fiddlejs : http://jsfiddle.net/re8jX/23/

Sander Elias

unread,
Jun 4, 2014, 3:14:00 AM6/4/14
to ang...@googlegroups.com
Hi Jason,

Yes it is working for me. It works even if I remove the 3rth parameter. It works in Chrome, Firefox and opera. 
Did you try cleaning your browsers cache?

Regards
Sander

Jason Villalon

unread,
Jun 4, 2014, 5:51:27 AM6/4/14
to ang...@googlegroups.com
can you jsfiddle it? yes i already cleared my browsers cache. im thinking maybe the metisMenu jquery plugin im using has some issue with angularjs... what do you think?


--
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/9DUifXyzKQg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Jun 4, 2014, 6:22:36 AM6/4/14
to ang...@googlegroups.com
Hi Jason,

I did not change a thing on your last fiddle, it just runs. 
When I remove the 3rth parameter, it keeps on working, across all those browsers. 
Your problem must lie somewhere else, as your fiddle runs without problem for me!

Regards
Sander

Jason Villalon

unread,
Jun 4, 2014, 11:28:27 AM6/4/14
to ang...@googlegroups.com
that is weird.

what is supposed to do is when you click the header menu it will collapse in the submenus.

here. i updated the fiddlejs: http://jsfiddle.net/re8jX/25/


--

Thiago Santos

unread,
Sep 30, 2014, 10:14:50 PM9/30/14
to ang...@googlegroups.com
Hi Jason,

I'm going through the same problem. You solved yours?

Jason Villalon

unread,
Oct 1, 2014, 12:05:16 AM10/1/14
to ang...@googlegroups.com
Hi,

I figured out the problem. turns out that the problem is in the jquery plugin.


i moved the plugin declaration at the top of js. then i commented

//if (!$.data(this, "plugin_" + pluginName)) {
       $.data(this, "plugin_" + pluginName, new Plugin(this, options));
//}

then voila the menu works after updating the $scope.menus. ^^

my question is how to reset the $.data of that element from angularjs.

Regards,
Jason Villalon

--

Thiago Gonçalves

unread,
Oct 1, 2014, 9:01:37 PM10/1/14
to ang...@googlegroups.com
Solved, thanks!

Aziz Hamraev

unread,
Dec 3, 2014, 1:06:29 AM12/3/14
to ang...@googlegroups.com
I'v not changed anything in plugin and menu works fine for me.
Reply all
Reply to author
Forward
0 new messages