0

The example below is extremely simple (edited after sp00m correct for the previous example response):

index.html: (part)

<table>
  <tr ng-repeat="r in [1,2,3]">
    <td ng-repeat="c in [1,2]" ng-mouseenter="name='John'">
      [{{r}},{{c}}]
    </td>
  </tr>
</table>
Hello {{name}}!

app.js:

app.controller('MainCtrl', function($scope) {
    $scope.name = 'World';
});

I am expecting the 'World' word being changed to 'John' being shown but nothing occurs when I am mousing over the cell.

I am posting plnkr below to show the problem. What am I doing wrong?! What am I missing? Is the problem with AngularJS 1.5.x plnkr is using that does not handle ng-mouseenter in <td>? Note that ng-repeat is not an issue - when I put manually new row this will not work either.

http://plnkr.co/edit/x1peSJyc50yqa1AM73GZ

Community
  • 1
  • 1
Grzegorz
  • 3,207
  • 3
  • 20
  • 43

2 Answers2

4

It is actually working, you just haven't defined alert in your $scope:

$scope.alert = function (...) { ... };
sp00m
  • 47,968
  • 31
  • 142
  • 252
  • Okay, I was expecting the javascript `alert` to be used. What about simple substitution of `'x=10'` and displaying `x`. Actually this does not work for me, so I replaced that with the `alert` one. PS. I will update my original input, but thank you for the quick response! – Grzegorz Mar 21 '17 at 15:35
1

Actually i had a same problem, i avoid to use the plain scope variables like this $scope.name, it may create some problems. so in the above plunker, declare a scope object something like this $scope.name = {firstName: 'World'} instead of plain scope variable. Then in html use this ng-mouseenter="name.firstName='John';", and it should work with this Hello {{name.firstName}}.

Sam
  • 2,275
  • 9
  • 30
  • 53
  • Dear Santhi - wow. When I changed to a structure it works. A bit frustraiting! I still wonder *why*. Is this the AngularJS bug....? Thanks a lot for your response. – Grzegorz Mar 21 '17 at 17:59
  • 1
    Hi @Grzegorz, sorry for late response, using dot notation (means object) is always preferred approach. Please check the answers one by one in here http://stackoverflow.com/questions/12618342/ng-model-does-not-update-controller-value , you will get a good understanding. – Sam Mar 22 '17 at 02:04