chieffancypants / angular-hotkeys

Configuration-centric keyboard shortcuts for your Angular apps.
http://chieffancypants.github.io/angular-hotkeys/
MIT License
1.68k stars 248 forks source link

Not updating the scope #238

Closed OwenMelbz closed 6 years ago

OwenMelbz commented 8 years ago

Hi Guys, really struggling to get this work as expected - not sure what I'm doing wrong to be honest.

But Im calling a function that pushes items to an array, however when this happens the scope doesnt seem to apply correctly as the new items do not appear in the list, however if i were to make a button that ran the same function it would work

You can see a plunker of it here -> https://embed.plnkr.co/fZ1fDORaDfAhRUK6uxhp/

here is the code as well

// Code goes here

angular.module('App', ['cfp.hotkeys']).
controller('Test', function($scope, hotkeys){
  $scope.title = 'loaded';

  $scope.items = ['default item 1', 'default item 2'];

  $scope.addItem = function(){
    $scope.items.push['im a new item'];
    alert('addItem fired');
  }

  hotkeys
  .bindTo($scope)
  .add({
    combo: 'e',
    callback: $scope.addItem
  })
});
<!DOCTYPE html>
<html ng-app="App">

<head>
  <link rel="stylesheet" href="style.css">
  <script src="https://code.angularjs.org/1.5.6/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-hotkeys/1.7.0/hotkeys.min.js"></script>
  <script src="script.js"></script>
</head>

<body ng-controller="Test">
  <h1>{{title}}</h1>
  <h2>here</h2>

  <ul>
    <li ng-repeat="item in items">{{item}}</li>
  </ul>
</body>

</html>
kroltan commented 6 years ago
$scope.items.push['im a new item'];

This line is wrong, you should use parentheses to call functions. If that fixes the issue, please close it, since it isn't a issue in this library.

OwenMelbz commented 6 years ago

Ah that was just a typo as I wrote a an example with loads of other stuff stripped out