That did it thank you!
On Friday, October 17, 2014 10:07:20 AM UTC-4, Sean Amoroso wrote:
>
> You toggleTabs is not a member of the scope. You either need to assign it
> to the scope or make intermediary functions on the scope.
>
> app.controller('TabController', ['$scope', 'toggleTabs',function($scope,
> toggleTabs) {
>
> this.toggleTabs = toggleTabs;
>
> }]);
>
>
> or
>
> this.toggleTabs = function() { toggleTabs.setTab(); }
>
> http://plnkr.co/edit/uEl5dAcveKgyyNOfrMsT?p=preview
>
>
> On Friday, October 17, 2014 9:57:11 AM UTC-4, Ian Cramer wrote:
>>
>> I have a tab setup in my application to hide/show content in the view. I
>> call the functions from the view with directives and would like to make the
>> logic re-usable in a service that is injected into other controllers as a
>> dependency.
>>
>> When the logic is inside the controller it works fine, but below you can
>> see what I have tried as far as a service and it is not working.
>>
>> And here is a Plunker with all this code:
>> http://plnkr.co/edit/liT7BIGlIRg9boH81NaY?p=preview
>>
>> Any ideas??
>>
>> HTML
>>
>> <ul class="expandingTab">
>> <li ng-class="{active: tabs.toggleTabs.isSet(1)}"><a href="#"
>> ng-click="tabs.toggleTabs.setTab(1)"> <span>Tab 1</span></a></li>
>> <li ng-class="{active: tabs.toggleTabs.isSet(2)}"><a href="#"
>> ng-click="tabs.toggleTabs.setTab(2)"><span>Tab 2</span></a></li></ul><div
>> ng-show="tabs.toggleTabs.isSet(1)">
>> <h1>Tab 1</h1></div><div ng-show="tabs.toggleTabs.isSet(2)">
>> <h1>Tab 2</h1></div>
>>
>> Controller
>>
>> var app = angular.module('myApp', ['services']);
>>
>> app.controller('TabController', ['$scope', 'toggleTabs',function($scope,
>> toggleTabs) {
>> }]);
>>
>> Service
>>
>> var tabsApp = angular.module('services', []);
>>
>> tabsApp.service('toggleTabs', function() {
>> this.tab = 1;
>> this.setTab = function(tabSelected) {
>> this.tab = tabSelected;
>> }
>> this.isSet = function(checkTab) {
>> return this.tab === checkTab;
>> }});
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.