In HTML file:
...
<ul>
<li><a href="#" ng-click="addFruit('Apple')">Apple</a></li>
<li><a href="#" ng-click="addFruit('Banana')">Banana</a></li>
<li><a href="#" ng-click="addFruit('Coconut')">Coconut</a></li>
</ul>
...
Controller:
...
$scope.addFruit = function(fruitName) {
$scope.fruitObject.name = fruitName;
};
$scope.fruitObject = {
name: '',
}
So, if I click the link in the HTML file, it changes fruitObject.name. I want to add the function that if I click the link with shift key, the value will be added to the fruitObject:
$scope.fruitObject = {
name: ['Apple', 'Banana']
}
- Can I do this without using a angular directive?
- And if I can/can't, could you write an example code?
JSFiddle: http://jsfiddle.net/6QcEc/
shiftKey
property of the Event object at any time to see whether the Shift key is being held down. – HartleySan Jul 30 '14 at 20:37