javascript - Angular.js best practice - extending controllers, overriding controller defaults -


here real-life angular problem can't wrap head around. love angular, issue bugging me lot right now.

what best practice extend existing controllers's functions, , use extended controller on other page of application? in other words: how controller inheritance in angular?

edited out - 23/09/2014, dont think description of original usecase helps visitors understand better i'm after here. think disctracts people real issue.

after half year think understand what's going on. pointed out in comment post, simplest answer services.

in optimal case, scope variables values gathered factory/service. still, might want use exact same controller 1 function: $scope.somefunction(){}, , keep rest. in case, have 'thin' controller logic, desirable controller design - may still end hundred or more lines of code. don't want being duplicated in other controller, because need controller logic (like $scope.somefunction() )

what do then?

the answer this:

  1. make sure did in order solve situation factories
  2. if abolutely did, go controller injection:

    .controller('childcontroller', function ($scope, $controller) {   'use strict';   $controller('parentcontroller', {$scope: $scope});   $scope.somefunction=function(){} }) 

it's simple. -- again, usually, things can solved factories..

hope find useful ;)


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -