1

I'm using angular-ui router and I have a very simple todo app I'm making to learn more about angular 1.4. If I have my <ui-view></ui-view> tags for my home controller, what is the best way to have a click in the header (to add a task effect my home view + controller?)

(My header HTML just has some anchor buttons, like add task, refresh list)

Header controller :

angular.controller('headerController', ['$scope', function($scope) {

  $scope.addTask = function(){
    //add a task or show toggle task form or call to something below in home controller
  }

}]);

My home controller:

angular.controller('homeController', ['$scope', 'getTasks', function($scope, getTasks) {

  $scope.todos = getTasks.load;

}]);

Should a service be made for something so simple? Or is this a job for rootscope, I know that rootscope should be avoided though as it pollutes global namespace. Thank you

fodma1
  • 3,485
  • 1
  • 29
  • 49
SD Dev
  • 335
  • 3
  • 10
  • What are you doing in `getTasks.load;`? – developer033 Aug 01 '16 at 19:22
  • Thats a service that calls $http to load from mongolab, then in my home view I used ng-repeat directive and interpolated the data. Basically its just a load function to get the data – SD Dev Aug 01 '16 at 19:40
  • So, it's correct... – developer033 Aug 01 '16 at 19:47
  • What I'm saying if I wanted to access a function from the header controller to the home controller... Is that bad practice? Say that it's even just a helloworld() function and I wanted to call it from my header controller, is that even possible – SD Dev Aug 01 '16 at 19:48
  • I guess its either a service, or emitting on $scope http://stackoverflow.com/a/9407953/6492029 – SD Dev Aug 01 '16 at 20:01

0 Answers0