Error between directive and controller

1

Files:
   index.html
   controllers / control.js
   directives / directiva.js
   directives / botao.html

* I have a function called $ scope.change (age) = function () {....}; in control.js
* in the directive I have templateUrl: "botao.html" and scope {function: "&"};
* in the index I have < \ function button="change (age)" > < / button >
* in botao.html I have

asked by anonymous 18.02.2017 / 00:56

1 answer

0

Do as follows:

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 the above: You have your directive and you can pass as age parameter, being restricted as an attribute. Already your controller just below referenced in the directive.

As you are using separate files for your controller, just put as you defined it.

    
20.02.2017 / 14:34