This doesn't work because it's not being handled asynchronously using jquery.
You need to use one of the 2 available options that Angular provides, that are ng-include directive or create your own directive for the menu.
ng-include
For this option you just need to:
1. delete the jquery load code (lines 30 to 33).
2. replace line 39 by:
Create your directive
This is the best option and the one that allows to properly isolate your code. On the other hand it's also the one that requires more work because in order to do it properly you should move some code from the Controller into the directive.
... a third option
Your existing code can still work but you need to "tell" Angular that you did some changes to the DOM and want it to have a look. For that you would need to use $scope.$apply(); and move line 31 into the controller making it something like:
This technique is the last resource, like in the cases where none of the above apply.
If you're getting serious about AngularJS I strongly recommend you to take some time to learn it properly and in depth. I leave you the 2 main training resources I usually recommend: PluralSight EggHead.io
Cheers!
DanteAdmin
ASKER
Hi Alexandre
And thanks again for your help
I did try that before without luck and the same now - no error code and nothing is included
Is there anything else I'm missing that has to be defined or activated ?
You are right and I'm trying to look up each task and do it the proper Angular JS way, sometimes I run out of time and have to cheat but I'm looking forward to my next "not so busy" period to do some proper Angular JS reading up
Regards,
Markus
Alexandre Simões
Some questions:
The ng-include isn't working?
Is the HTML being displayed?
Can you show me your HTML now that you changed it to use the ng-include directive?
when you use ng-include you create a chil scope, so that might be part of your issue.
you would be much better off using ui-router (which is eventually going to be built right into angular) and define views.
you have to break out of the jquery frame of mind altogether. my advice would be to remove jquery from your page until you are a point where you know how to integrate it into your app properly by writing directives.
there is no point in taking shortcuts with angular - you will create more headaches than it's worth. for better or worse, angular is a very opinionated framework. that's why everyone talks about doing things the 'angular way'. as much as i dislike doing thing things anybody's way, this is a time when doing it their way will really benefit you in the long run. and doing it any other way is unintuitive and complicated.
Kyle Hamilton
btw, you are calling jquery twice, so if you do decide to jquery, you still have to remove one of them.
DanteAdmin
ASKER
I think I did per instructions i.e. delete the old lines in the head and replaced the include code with the ng control instead
does the click action even enter the function? put a log at the top of the function
Kyle Hamilton
you still have two calls to jquery: line 28, and line 98 in the code posted above. This may not be the cause of the problem described, but it will definitely cause other problems
DanteAdmin
ASKER
I've removed the bottom one so only one call there now
The include is not displaying any data so I can't test the click
If I simply include the code on the page the click works fine
I think I will spend this morning looking at the directives etc as I feel they will come in handy plenty of times
Still a bit worried re the rest of my code if a simple call like "<div ng-include="inc/WhyQ-menu.htm"></div>" isn't working
Open in new window
This doesn't work because it's not being handled asynchronously using jquery.You need to use one of the 2 available options that Angular provides, that are ng-include directive or create your own directive for the menu.
ng-include
For this option you just need to:
1. delete the jquery load code (lines 30 to 33).
2. replace line 39 by:
Open in new window
Create your directive
This is the best option and the one that allows to properly isolate your code. On the other hand it's also the one that requires more work because in order to do it properly you should move some code from the Controller into the directive.
... a third option
Your existing code can still work but you need to "tell" Angular that you did some changes to the DOM and want it to have a look. For that you would need to use $scope.$apply(); and move line 31 into the controller making it something like:
Open in new window
This technique is the last resource, like in the cases where none of the above apply.If you're getting serious about AngularJS I strongly recommend you to take some time to learn it properly and in depth. I leave you the 2 main training resources I usually recommend:
PluralSight
EggHead.io
Cheers!