0

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!");
};

3 Answers 3

3

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");
    };
});

jsFiddle

Sign up to request clarification or add additional context in comments.

Comments

1

It should work fine. Take a look here.

4 Comments

This looks like it works in JSFiddle, but for some reason I can't get it to run in visual studio correctly. Any suggestions?
Sorry, I am not familiar with VS.
Okay, I also did this in other text editors and it gives the same result: Customer Info {{getCustomerName}}
You should post the HTML.
0

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>

1 Comment

For some reason this still doesn't work. Any other suggestions? Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.