I'm new to Angular and I have been working on small project. I have a question about directives and ng-click.
Every time I click on the div tag to setoff the setlock() function it never fires. Could this be caused by my directive and controller being in separate files? And is there a way to make this work using link: ?
Thanks.
Directive.js
(function(){
'use strict';
angular
.module('widget.ballslot')
.directive('ballSlot', ballSlot);
function ballSlot(){
var directive = {
restrict: 'E',
scope: true,
templateUrl: 'app/widgets/ballslot.html',
controller: 'Ballslot',
}
return directive;
}
})();
Controller.js
(function(){
'use strict';
angular
.module('widget.ballslot')
.controller('Ballslot', Ballslot);
function Ballslot() {
var vm = this;
vm.locked = true;
function setlock() {
vm.locked = !vm.locked;
};
};
})();
page.html
<div data-ng-controller='Ballslot as vm' class='ball'>
<div id='background-purple' ng-click='vm.setlock()'>
<i class="fa fa-lock" ng-hide="vm.locked"> </i>
<i class="fa fa-unlock-alt" ng-show="vm.locked"></i>
</div>
</div>