2014년 12월 30일 화요일

[AngularJS] What is the best way to pass values between controllers

Which one is the better way to pass values from one controller to another controller? either using $rootScope or by setting and getting values using service?
Some one suggest me the good approach.



You're better at sharing data with a service. This way is more explicit which component maintains data. As best practices goes, avoid sharing data on scope, either by $rootScope or child/inherited scopes/controllers.




Hi André Werlang,
I need to know whether any issues will happen (like performance issue) or not while using $rootScope.



Performance is the same. However, it's a poor choice for those concerned with maintainability. As application grows, that can lead to name clashes and lost focus on responsibility over data and/or functions. Usage $rootScope will never figure in a best practices article and could even go away as angular evolves (>=2.0...) .



I've not done this myself but for passing "values" between controllers I'd consider https://github.com/postaljs/postal.js


댓글 없음:

댓글 쓰기