angular-ui/bootstrap — pull request #834 by chrisirhc (2013-08-17 00:03:21+00:00)
Title: fix(tabs): Initial tab selection

Before I go to explain, there are up to two expressions that indicate
whether a tab is active:

1. `active` variable in the isolate scope of the tab directive
2. The expression from the active attribute (`attrs.active`), I'll
call this the activeAttrExp.

Two things are going on:

During initial linking (adding of tabs), the `active` variable in the tab's isolate scope tracks the active tab. When the first tab is added, it's `active` is set to true since there's no way to know if subsequent tabs are active since they haven't been added yet. As such, at this point, it is not meaningful to set assign the activeAttrExp with the value of `active`. At least not until all the tabs have been added. Hence, a good time would be to wait until the next $digest cycle.

The $watch expression is evaluated asynchronously after initialization. As such, there is a chance that the `active` variable gets initialized a second time using the activeAttrExp. Since we're already initializing it manually, and the `active` variable should now be carrying the *truth*, avoid this.

This fix is ugly because the logic for the two-way binding of `active` and the activeAttrExp is complex. Consider refactoring the implementation for maintaining the two-way binding (see ngModel for inspiration).

Fixes #747.