0

So I have a clearNotification function I want to trigger when I click the '#upload' button. I set an ng-click on that button to trigger notify().

What I'm wondering is if it's a violation of separation of concerns to put that clearNotification function within notify(). Is it better to add that as another ng-click on '#upload'? Or is this where directives come in?

Would love any input on this.

So far, this is what my code looks like:

HTML:

<button id="upload" ng-click="notify()">Upload</button>

Controller:

$scope.clearNotification = function() {
  $scope.notification = '';
};

$scope.notify = function() {
  $scope.clearNotification();
  ...
};
2
  • Do you really need to define clearNotification in the scope? Do you use it somewhere like in ngClick? You maybe only need normal function definition function clearNotification() {...}. Commented Jul 17, 2014 at 20:57
  • yea that is what I will be doing if its better to keep it the way it is now. Commented Jul 17, 2014 at 20:59

1 Answer 1

1

There's nothing wrong with calling controller functions from other controller functions.

If the clearNotification function has some business logic, then add it to a service(and inject that service into your controller). Thats the correct way to seperate components.

Should this be a directive? Only if this is a re-usable component that can live alone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.