Consider the following controller
angular.module('app')
.controller('formCtrl', ['$scope', '$http', function($scope, $http) {
$scope.var = 1;
$scope.updateData = function () {
debugger; // <-- $scope is undefined here!
}
}]);
dirrective is as follows...
angular.module('app')
.directive('formL', function() {
return {
restrict: 'E',
scope: {
items: '=info'
},
controller: 'formCtrl',
templateUrl: 'js/form/form.html'
};
});
Template is the following
<form class="form-horizontal" ng-controller="formCtrl as controller">
<input type="button" value="BTN" class="btn btn-success" ng-click="updateData()">
</form>
That does not seem to be the common problem (at least I did not found something simmilar in Google and on SO), when I hit button and get into controller $scope
is undefined
. And at the same time this
is equal to $scope
as it should be.
What should I do to make $scope
be visible inside updateData
?
PS. angular
version is 1.6.5
UPDATE. I've change directive name from form
to formL
into above template. form
is definetelly not the best name for a dirrective, but it's not the name I have in project, it's a bad simplification of the name for this question. So the problem is not caused by the name of dirrective