Directive not recognizing click event on table row

Following up on the previous inquiry: How can I pass my model to the Directive?

Although the directive successfully displays the data, the ng-click function seems inactive.

This is how my partial page currently appears:

<div>selected user:{{selectedUser.UserName}} </div>

<div user-list data-users="users"></div>

Here's how my directive looks now:

tsUui.directive('userList', function(){
    return{
        restrict: 'A',
        template: '<table>'+
                    '<tr>'+
                        '<th>User Name</th>'+
                        '<th>First Name</th>'+
                        '<th>Last Name</th>'+
                        '<th>Email Address</th>'+
                    '</tr>'+
                    '<tr ng-repeat="user in users" ng-click="selectUser(user)">'+
                        '<td>{{user.UserName}}</td>'+
                        '<td>{{user.FirstName}}</td>'+
                        '<td>{{user.LastName}}</td>'+
                        '<td>{{user.Email}}</td>'+
                    '</tr>'+
                '</table>',
        scope:{
                selectedUser: '=',
                users: '='
        },
        link: function (scope, elem, attrs){
            scope.selectUser = function(user){
                console.log("hi");
                selectedUser=user;
            };
        }
    }
});

The data is being displayed correctly, but upon clicking a row, there are no changes - no console logs and the selected user binding remains unchanged. What am I missing here?

Update: The console does log the interaction, but the selected user binding remains stagnant...

Answer №1

It seems the correct way to do it is as follows:

scope.activeUser = selectedUser;

I also made some adjustments to the partial:

<div>Selected User: {{selectedUser.Name}} </div>

<div user-list data-users="users" active-user="activeUser"></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Authentication with AngularJS and Java, managing $scope

My current system setup includes: front-end = AngularJS back-end = Java EE7/REST-API Both applications are operating on Wildfly 8.2 using Undertow as the application server. One of my main concerns is about the authentication process: Should I impl ...

Angular: attaching an identification number to an API endpoint

I encountered a problem that has left me puzzled: I am attempting to remove a row from a table by passing the ID of that row (known as the record) through the path of my API. However, for some reason it is not being recognized. Strangely enough, when I sub ...

What could be causing the three.PointLightHelper to fail in my script?

I am encountering an issue with the line of code scene.add(new THREE.PointLightHelper(bluePoint, 3)); in my code snippet below: var bluePoint = new THREE.PointLight(0x0033ff, 100, 500); bluePoint.position.set( 500, -500, 25 ); scene.addLight(bluePoint); s ...

Why is it that I am unable to utilize the post data stored in $var within my PHP document when making an Ajax call?

Hey there! I've got this function that makes an ajax call. But, for some reason, the $value I'm passing isn't defined in my showuser.php file. Can you help me figure out why? function showUser2(value) { var xhr = new XMLHttp ...

Utilizing AngularJS to achieve similar functionality to window.bind()

When trying to set the context of a function and pass it as a callback, I am following this approach: myController.myService.validateToken(param) .then( myController.myService.getToken.bind( myController.myService ) ); myController.myService.getToken ...

Retrieving entities from a text

I found a script on the Webdriver.io website that looks like this (adjusted for testing) const { remote } = require('webdriverio'); var assert = require('assert'); ;(async () => { const browser = await multiremote({ ...

Pagination using Laravel 4, Angular JS, and the latest Twitter Bootstrap 3 features

Update: In my application built with Laravel 4 and Angular JS, I am in need of pagination functionality. While there is an option to use the angularui-bootstrap pagination, I have decided to explore and integrate the features of Laravel pagination with An ...

Creating a blank grid using ng-repeat in angularJS

I'm attempting to create an empty grid using angularJS, but I've only been working with it for 2 days so I'm not very experienced. This is what I have come up with so far: <!doctype html> <html ng-app> <head> < ...

Enhancing stroke precision and aliasing in SVG images

Need help creating sharp 1px thick black lines for an animated speech bubble using SVGs. The anti-aliasing on the strokes isn't crisp and has a smudged look, despite efforts to fix it by rounding calculations. What can be done to achieve clean, precis ...

Understanding how to accurately pair specific data points with their corresponding time intervals on a chart

I'm currently working with apexcharts and facing an issue with timestamps. I have data for sender and receiver, each having their own timestamps. The x-axis of the graph is based on these timestamps, but I am struggling to map the timestamp with its r ...

Incorporating AJAX into ASP Classic through an include file

Can I change the content of the #result div using ASP Classic's Include.File on click with a Bootstrap nav? HTML <body onload=""> <nav class="navbar navbar-light bg-light sticky-top shadow"> span><%= ...

Spring Ajax response returns empty objects in the list

I'm currently developing a locker management system which includes an update history feature for the lockers. I am interested in implementing Ajax to retrieve a list of this update history, limited to X entries. However, when I return either List<L ...

Analyzing file data while uploading the file

Does anyone have a solution for extracting the content from an uploaded file in express/nodejs without saving it as a temporary file? I have code that successfully pipes the input to a filestream, but I'm struggling to deserialize the upload to a pla ...

Trouble with modifying style in Google Chrome and Internet Explorer prior to AJAX request

When utilizing AJAX, I have a common practice of setting up a loading indicator before each request to inform the user about the short wait. Usually, this is achieved by adding an animated loading gif. Interestingly, when performing this action in Firefox, ...

Error: Unable to process task due to an unexpected TypeError: _this.tasks.push is not a valid function

After spending the entire day browsing the internet, I need help. I am using a Vue.js app and in my component, I assign my data array variable to a response from the server. However, when I attempt to push some data to an array, I encounter this error: Unc ...

Unable to locate web element using Selenium in C#

Here is the HTML code I am currently using: <div class="modal-footer"> <button class="btn btn-primary" type="button" value="Show Alert" ng-click="questions.getIrMessage()" data-dismiss="modal">Confirm</button> <button class ...

Is it possible to utilize TypeScript for enforcing type safety in AngularJS templates?

Is it possible to utilize TypeScript in Angular 1.6 templates, following best practices such as components/bind-to-controller usage? Consider the following template code: <div>{{$ctrl.children[0].name}}</div> If we know the type of the contr ...

Algorithm that eliminates the second instance of a character in a given string using regular expressions

Struggling to craft a JavaScript function that eliminates the second instance of a character using regular expressions. Here is my current function: var removeSecondOccurrence = function(string) { return string.replace(/(.*)\1/gi, ''); } T ...

The resolution error has occurred: { Issue: Module 'npm-watch' not found

After successfully running "npm install" and installing all packages in the node_module folder, I encountered errors when running the "npm start" command in the command prompt. D:\INSM-HTML-Player>npm start <a href="/cdn-cgi/l/email-protection" ...

What is the best way to transfer data from a PHP array to a jQuery array?

I can't seem to grasp the concept of transferring a PHP array to a jQuery array. I am trying to achieve something similar to this: var jQueryArray = <?php $phpArray; ?>; Could someone please provide guidance on how I can accomplish this? ...