javascript - Angular js same $scope in separated files -
i have angular js controller witch getting bigger , bigger, want separate functions separated files, cannot access $scope of controller in other files. best practice doing this?
for example if controller in app.js
formappcontrollers.controller('maincontroller', function($scope,$translate) {}); i want able use same $scope in functions.js file.
this might not answer you're looking for, i'd other way around: i'll define services , use them in controllers getting crowded. way, can avoid accessing $scope elsewhere.
something service.js have:
var someservice = angular.module('someservice'); someservice.factory('subservice', function () { var methodname = function (arg) { // } }); and in angular module application logic, like:
var mainapp = angular.module('mainapp', ['someservice']); and ofcourse;
mainapp.controller('mainctrl', function ($scope, subservice) { // controller stuff subservice.methodname(arg); // etc });
Comments
Post a Comment