Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
fix(macMenu): Fixed menu index bi-directional binding not working pro…
Browse files Browse the repository at this point in the history
…perly
  • Loading branch information
adrianlee44 committed Sep 18, 2013
1 parent edb34cb commit db719b0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/directives/menu.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ A directive for creating a menu with multiple items
- `index` - {Integer} Item index
@param {Object} mac-menu-style Styles apply to the menu
@param {Expression} mac-menu-index Index of selected item
- `index` - {Integer} Item index
###

angular.module("Mac").directive "macMenu", [
Expand All @@ -24,6 +23,7 @@ angular.module("Mac").directive "macMenu", [
items: "=macMenuItems"
style: "=macMenuStyle"
select: "&macMenuSelect"
pIndex: "=macMenuIndex"

link: ($scope, element, attrs, ctrls) ->
$scope.selectItem = (index) ->
Expand All @@ -32,8 +32,11 @@ angular.module("Mac").directive "macMenu", [
$scope.setIndex = (index) ->
$scope.index = index

$scope.$watch "index", (value) ->
getter = $parse attrs.macMenuIndex
if getter.assign? and value
getter.assign $scope.$parent, value
if attrs.macMenuIndex?
$scope.pIndex = parseInt(index)

# sync local index with user index
if attrs.macMenuIndex?
$scope.$watch "pIndex", (value) ->
$scope.index = parseInt(value)
]

0 comments on commit db719b0

Please sign in to comment.