0

i am having a core controller

(function() {
    "use strict";

    function FieldSettingsOverlay($scope, localizationService, formService, userService) {
        var vm = this;
        vm.changeValidationType = changeValidationType;

        vm.validationTypes = [{
            "key": "number",
            "pattern": "^[0-9]*$"
        }, {           
            "key": "url",
            "pattern": "https?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}"
        }];

        function changeValidationType(selectedValidationType) {
            console.log("Parent")
        }
    }
    angular.module("umbraco").controller("UmbracoForms.Overlays.FieldSettingsOverlay", FieldSettingsOverlay);

})();

from this parent controller i have an array called vm.validationTypes , this is currently having only 2 objects but i have to add 3 or 4 objects.

so i have created a another controller by extend the core controller

// CustomValidation

angular.module("umbraco").controller('FromValidationCustomController', function ($scope, $controller) {
  'use strict';

console.log("inistiate")
  angular.extend(this, $controller('UmbracoForms.Overlays.FieldSettingsOverlay', {$scope: $scope}));
  $scope.changeValidationType=function(){

    console.log($scope.validationTypes)
  }
})

new extended controller using the same function called changeValidationType it is not even calling it where as only parent function calling

any idea what am i missing ? why this controller inside function not calling

Gayathri Mohan
  • 2,924
  • 4
  • 19
  • 25

1 Answers1

0

The posted code has issue. Please check the updated minimum code section that works:

(function(angular) {

 var module = angular.module('umbraco',[]);

 module.controller('UmbracoForms.Overlays.FieldSettingsOverlay', function($scope, $document) {
    this.validationTypes = [{
            "key": "number",
            "pattern": "^[0-9]*$"
        }, {           
            "key": "url",
            "pattern": "https?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}"
        }];
  this.changeValidationType = function() {
     console.log("Parent")
   return this.validationTypes;
  };
 });

})(angular);
var module = angular.module('example1',['umbraco']);
module.controller('FromValidationCustomController', function($scope, $controller) {
console.log("inistiate");
  angular.extend(this, $controller('UmbracoForms.Overlays.FieldSettingsOverlay', {$scope: $scope}));
 });
  
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.js"></script>

<div ng-app="example1">
    <div ng-controller="FromValidationCustomController as C">
        <span><b>From Parent Controller:</b> {{C.changeValidationType()}}</span>
    </div>
</div>
I. Ahmed
  • 2,438
  • 1
  • 12
  • 29