Reputation: 2269
I am working on a project and want to have an alert box pop up when the user clicks on the input section. However, I am having issues. Any suggestions?
My html/AngularJS code:
<li ng-click="showCustomerList()" class="clickable">
<label>Customer Info</label>
<input readonly = "readonly" ng-class = "{editing: ShowCustomerList.isOpen()}" placeholder = "text" value = "{{getCustomerName}}"/>
</li>
My JavaScript/AngularJS code:
$scope.showCustomerList = function () {
alert("This is the popup!");
};
Upvotes: 0
Views: 14099
Reputation: 9053
Try adding an ng-click directive to an anchor element:
<input readonly="readonly" ng-class="{editing: ShowCustomerList.isOpen()}" placeholder="text" value="{{getCustomerName}}"/>
<a href="" ng-click="showCustomerList()">Click Me</a>
Upvotes: 0
Reputation: 4038
I guess you are missing the ng-app directive or putting it inside the head tag. Try putting it inside the html tag or the body tag.
HTML :
<body ng-app="TestApp">
<div ng-controller="MyController">
<ul>
<li ng-click="alertMe()" class="clickable">Click me</li>
</ul>
</div>
</body>
myjs.js
var myModule = angular.module("TestApp", []);
myModule.controller("MyController", function($scope){
$scope.alertMe = function(){
alert("Hello Everyone");
};
});
Upvotes: 3