Nested HTML pages with AngularJS
I am trying to create a switch between two tables. I have a button that, when clicked, will change the search parameter in the url using $location.search
. I have each table saved in separate HTML files.
I was wondering if createElement ('div') could be used to insert an HTML file into another (I was thinking about a directive in the angular module). If this is not possible, then how can I embed an HTML file into another HTML file from within a module?
Thank!
source to share
As suggested, you should take a look at ui-router and define the nested view depending on the url parameter.
If you don't need a complete router, you can do it using ng-show in angular.
Here is a plunker as an example
I added an ng-show attribute to each table:
ng-show="!switchTable" for table1
ng-show="switchTable" for table2
And I added this ng-click to the button:
ng-click="switchTable = !switchTable
source to share