Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

when i call a function which is defined in controller am getting function not defined error.

Uncaught ReferenceError: deleteBook is not defined

<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8'>
  <title></title>
<body>

<div ng-app="myApp" ng-controller="customersCtrl"> 
<ul style="list-style:none;">
  <li ng-repeat="x in name">
    <a onclick="deleteBook({{ x.id }})" href="javascript:void(0);">{{ x.name + ' - ' + x.author }}</a>
  </li>
</ul>
</div>    
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script type="text/javascript">
    var app = angular.module('myApp', [] );
    app.controller('customersCtrl', function( $scope , $http ) {
        $scope.deleteBook = function ( pId ) {
            console.log( pId );
        }       
        $http.get("http://localhost/tangu/books.php")
        .then(
             function(response) {
                console.log(response);
                $scope.name = response.data;
             }
        );  
    });
</script>
</body>
</html>
share|improve this question
up vote 0 down vote accepted
 <a onclick="deleteBook({{ x.id }})" href="javascript:void(0);">{{ x.name + ' - ' + x.author }}</a>

Try this instead of what is written above.

 <a ng-click="deleteBook(x.id)"</a>

Given that deleteBook function is there in your respective controller.

share|improve this answer
    
this works but may i know why we didn't used {{ x.id }} – user1679267 20 hours ago
    
Because data binding is not needed where angular directive is used. ng represents the directive there. – Gandalf the White 20 hours ago
    
Without the directive we might need the databinding like in case this tooltip="{{image.test}}" – Gandalf the White 20 hours ago
    
accept the answer if your problem is solved – Gandalf the White 20 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.