angularjs - How to load Second controller on click of button from FirstController in AngualrJS -


Questions on loading another controller on the click of a button

  • Do I use the controller Inside any other controller (as my example is below)
  • When clicking on "showmore" div, is it possible to call another controller to load content in the dialog?

page1 Jsp

& lt; Div ng-controller = "first controller" & gt; & Lt; Div ng-click = "showMore ()" & gt; Lesson 1 & lt; / Div & gt; & Lt; Div ng-click = "showMore ()" & gt; Lesson 2 & lt; / Div & gt; & Lt; / Div & gt; & Lt ;! - My modal dialog - & gt; & Lt; Script type = "text / ng-template" id = "secondController.html" & gt; & Lt; Div ng-controller = "second controller" style = "top: 20px; left: 300px; condition: complete;" & Gt; & Lt; Div ng-repeat = "Content in content" & gt; {{Content}} & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Script & gt;

Page 1.js

  var app = angular Module ('MyApp', []); App.controller ("first controller", function ($ radius, $ template cache) {$ scope.show more = function () {$ template cache ("second controller"); // what to do to open second controller // Should be // and populate "content" div}});  

  • Can I use the controller inside an administrator (such as My example is below)

Yes, the way you set up your template will allow you to use a different controller for model sub-section. However it would be better to move forward in other ways.

  • On the click of "Divide more", is it possible to call another controller to load content in the dialogue?

Angular Controllers rarely interact directly, so most services are passed through services or broadcasts through your services. In this case, you need to either populate the content value in parent realm (first controller) or second controller. In the latter case, you may need to change the ng-repeating reference for the second controller. Contract

I suggest that the easiest way to go about the desired functionality, as I understand your intentions, such as the Functional Angular UI: or ngDialog unless you have no specific reason, In both of these projects, the model is a good example of the dialog, which you can adjust to your controllers according to your needs.


Comments