Error between Directive and controller

Asked

Viewed 51 times

1

Archives:
     index.html
     controllers/control.js
    Directives/directive.js
   Directives/boot.html

*i have a function called $Scope.change(age) = Function(){.... }; in the control.js
*in the directive I have templateUrl: "botao.html" and Scope{function: "&"};
*no index tenho < botao funcao="change(age)"></botao>
*in the.html button I have < button ng-click="function(20)"> Test </button>

I want to call the function change from within the directive but keeps giving the following error Typeerror: Cannot use 'in' Operator to search for 'change' in 1

1 answer

0

Do it this way:

angular.module('').directive('SuaDiretiva', function() {
    return {
        restrict: 'A',
        templateUrl: 'botao.html',
        scope: {
            idade: '=',
        },
        controller: _SeuController
    }
});

var _SeuController = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {

    $scope.mudar = function (idade) {
       //Sua funcao usando idade, ou scope.idade
    };
}];

Explaining about the above: You have your directive and you can pass as parameter age, being restricted as attribute. Already your controller just below referenced in the directive.

Since you are using separate files for your controller, just put as you have set the same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.