AngularJS controller inherits from another controller _ AngularJS

Source: Internet
Author: User
This article introduces the contents of AngularJS controller inherited from another controller. I think the introduction is very good and has reference value. If you are interested, refer to the Controller inheritance in AngularJS, commonly used is the scope nesting scope. By default, when an attribute cannot be found in the current scope, it will be searched in the parent scope. If it cannot be found until $ rootScope is found.

However, in some cases, rootScope is our controller, and it is impossible to write a large number of public attribute methods into rootScope.

For example, there are multiple similar pages with elements such as bread, search bar, toolbar, and table. The elements such as a bread table are considered as directive, there will inevitably be many similar configurations that need to be transferred from the controller to the component, and many tool-class methods will be generated for processing data, etc, at this time, it is difficult to repeatedly write the same code in the controller of each page, and inheritance is required.

The solution was found on StackOverflow. AngularJS has already considered this situation and provided $ controller

Var app = angular. module ('angularjs-starter ', []); app. controller ('parentctrl ', function ($ scope) {// I'm the sibling, but want to act as parent}); app. controller ('childctrl ', function ($ scope, $ controller) {$ controller ('parentctrl', {$ scope: $ scope}); // This works });

The above section describes the AngularJS controller inherited from another controller. I hope it will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.