?^^ used in in Angular JS 1.x Component

I am working on Angular JS 1.x (I know the FW is outdated :)) where in I noted the following convention to be used much in component configuration.

require: {
      componentContoller1: '^componentContoller1',
    }, 

I understand that we asking angular to get componentContoller1’s controller instantiated and bind it to a property in current component, but I also noticed following convention like

require: {
          componentContoller1: '?^^componentContoller1',
        }, 

Can someone tell me what is the difference here using ?^^, I tried google and angular doc but could not get a clarity. Any help great and thanks.

Complete configuration or set up will be like

angular.module('moduleName').component('componentName',{
templateUrl: "path to template",
require: {
          componentContoller1: '?^^componentContoller1',
         },
controller(){ //code }
})

Answer

From the official documentation (https://docs.angularjs.org/api/ng/service/$compile#-require-)

  • (no prefix) – Locate the required controller on the current element. Throw an error if not found.
  • ? – Attempt to locate the required controller or pass null to the link fn if not found.
  • ^ – Locate the required controller by searching the element and its parents. Throw an error if not found.
  • ^^ – Locate the required controller by searching the element’s parents. Throw an error if not found.
  • ?^ – Attempt to locate the required controller by searching the element and its parents or pass null to the link fn if not found.
  • ?^^ – Attempt to locate the required controller by searching the element’s parents, or pass null to the link fn if not found.

Leave a Reply

Your email address will not be published. Required fields are marked *