user567
user567

Reputation: 3852

using a service in the view with angularjs

I want to share data between a view and a controller so I create a service. I tried to use the service in the view to set the data but it's not working. I think the problem is this line of code

<a .... ng-click="myService.setData('someString')">

Upvotes: 0

Views: 20

Answers (1)

Mindastic
Mindastic

Reputation: 4121

In your controller you can include the service and then do something like:

$scope.myService = $myService;

Or better:

$scope.setData = function(data) {
  $myService.setData(data);
}

And change your html by:

<a .... ng-click="setData('someString')">

Upvotes: 1

Related Questions