0

In my app I have index.html where there is ng-view directive. Inside that directive I add information from main.html as defalut - it's a table of names and links. By clicking a link the content of ng-view updates and information about the particular link from link.htmlappears. Please, see my index.html:

<!DOCTYPE html>
<html lang="en" ng-app="app">
<head> ... </head>
<body ng-controller="myCtrl">
    <h1>AngularJS</h1>
    <ng-view></ng-view>
</body>
</html> 

My main.js:

angular
    .module('app', ['ngRoute'])
    .config(function($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'partials/main.html'
            })
            .when('/link/:id', {
                templateUrl: 'partials/circle.html',
                controller: 'linkCtrl'
            })
            .otherwise({
                redirectTo: '/'
            })
    })
    .controller('myCtrl', function($scope) {
        $scope.obj = [
            {name: "aaa", link: "000"},
            {name: "bbb", link: "111"},
            {name: "ccc", link: "222"}
        ];
        $scope.clickFunc = function() {
            alert('Im doubleclicked');
        };
    })
    .controller('linkCtrl', function($scope, $routeParams) {
        $scope.id = $scope.obj[$routeParams.id];
    });

Here is my main.html:

<h2>Information</h2>
<table>
    <thead>
    <tr>
        <td>Name</td>
        <td>Link</td>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="link in obj">
        <td>{{ link.name }}</td>
        <td><a href="#/link/{{ $index }}" ng-dblclick="clickFunc()">{{ link.link }}</a></td>
    </tr>
    </tbody>
</table>

And here is link.html:

<p>Welcome to the new link {{ id }}</p>
<a href="#/">Back to home</a>

I also need to be able to double click the same link. The question is how to do that because adding ng-dblclick directive doesn't work. Is there any way to make it possible? I've seen here a similar question but I didn't see the answer. Thank you for your help in advance!

Community
  • 1
  • 1
Ms.Smith
  • 413
  • 1
  • 7
  • 15
  • You want a click event and a double click event on the same element? The first event would always fire before the double click event is raised. – Dominic Scanlan Jul 12 '16 at 12:51
  • @DominicScanlan, I want to be able to double click on my *a* element but at the same time I want my routing to work as well. Of course, this is an example from my real project that was simplified for SO. I don't need a separate single click on my element unless it routes to another link. – Ms.Smith Jul 12 '16 at 12:58

0 Answers0