Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Professional AngularJS
|
BOOK: Professional AngularJS
This is the forum to discuss the Wrox book Professional AngularJS by Valeri Karpov, Diego Netto; ISBN: 978-1-118-83207-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional AngularJS section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2015, 01:08 PM
Authorized User
 
Join Date: Jan 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to data_art Send a message via AIM to data_art Send a message via MSN to data_art Send a message via Yahoo to data_art
Question Page 162 - Writing Your Own Event Handler Directive

I'm using AngularJS 1.3 on IE9 with the following html:

HTML Code:
<!doctype html>
<html ng-app="myApp">
<!-- Directives-Basics -->
 <head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Data Binding with Buttons</title>
 
  <script src="angular.js"></script>
 
 </head>
 
 <body>
 
  <!-- Angular is loaded before the Angular Functions -->
 
  <h1>0403 - Directives Basics with ng-click</h1>
  <div my-ng-click>Increment Counter</div>
 
  <!-- Angular Functions -->
  <script type="text/javascript">
   // Main Application Module
   var appModule = angular.module("myApp", []);
 
    appModule.directive('myNgClick', function() {
 
     return function(scope, element, attributes) {
 
      // alert(element);
      // alert(attributes("my-ng-click"));
 
      element.click(function(){
 
       scope.$eval(attributes.myNgClick);
       scope.$apply();
 
      });
 
      alert(scope);
 
     };
 
    });
 
  </script>
 
 </body>
 
 <!-- Root Scope -->
 <!-- $scope = a place to store the data for this view -->
 
 <!-- Directives -->
</html>
I get the following error on the console:

TypeError: Object doesn't support property or method 'click'<div my-ng-click="">

How do I fix this error?
__________________
I was in a forest and a tree fell right in front of me and I didn't hear it - Stephen Wright.
 
Old July 18th, 2015, 01:41 AM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2015
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Talking

Method 'click' is a jquery function and is not native to angularjs. If you compare the chapter code to your example then you can see that you've omitted the script reference to import jquery.

<script src="https:////ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

You'll also solve a lot of issues by uninstalling IE.
 
Old December 16th, 2015, 07:24 PM
Registered User
 
Join Date: Nov 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by data_art View Post
TypeError: Object doesn't support property or method 'click'<div my-ng-click="">

How do I fix this error?
I get the same thing with IE 11. If you use ng-click instead of my-ng-click, it'll work, but it rather defeats the whole purpose of the example. I've spent about an hour on this, and have decided that I'm going to stop wasting my time and go back to running the examples in Chrome. My experience with the book has been the Chrome works better, excepting the things that don't work in Chrome but do work in IE, and that Firefox doesn't work at all.

In my workplace we're ditching IE for Chrome.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Button event handler sachingoel0101 Javascript 4 July 5th, 2012 07:02 AM
Chapter 14 Page 488 - Event handler missing kiwibrit BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 August 13th, 2009 04:18 AM
Event handler samir_katore Pro VB 6 6 June 8th, 2006 01:22 PM
Event handler problem carro123 Javascript How-To 1 May 20th, 2005 03:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.