Instantiate other AngularJS-controller with a CommonController when using IIFE -


i have project lot of models going managed same controller-code exception calling different services.

the way i'm handling instantiating crud-controller common code every custom controller , redirecting service-call changing variable inside custom controller. i.e. vm.service.get() inside crud-controller changes setting vm.service = teamservice; in custom controller.

this how instantiate crud-controller custom controllers @ moment:

$injector.invoke(crud, this, {$scope:$scope}); 

this works fine, don't know if right way share common controller code. maybe possible instantiate service use? because question have (if way of doing correct), how access other controllers while using iife? right not using iife since have not figured out way so.

i have tried angular.module('app').controller('crud') not work.

i.e: how access primaryctrl's edit function without using $injector or relying on $scope inheritance? http://jsfiddle.net/tcvhn/62/

it looks example uses angular 1.0.x supports global controllers out of box. that's how done more recent angular, without going deep perils of js inheritance.

'use strict';  (function (root, angular) {     root.ctrls = root.ctrls || {};      var primaryctrl = function ($scope) {         var self = this;         console.log('primaryctrl constructor', self, $scope);     };     primaryctrl.prototype = {         items: ['item 1', 'item 2'],         edit: function (item) {             //do stuff         }     };     primaryctrl.$inject = ['$scope'];      root.ctrls.primaryctrl = primaryctrl; })(this, angular);  (function (root, angular) {     root.ctrls = root.ctrls || {};      var secondaryctrl = function ($scope) {         var self = this;         console.log('secondaryctrl constructor', self, $scope);     };     secondaryctrl.prototype = angular.extend({},         root.ctrls.primaryctrl.prototype,         {             items: ['stuff 1', 'stuff 2']         }     );     secondaryctrl.$inject = ['$scope'];      root.ctrls.secondaryctrl = secondaryctrl; })(this, angular);  var app = angular.module('app',[]); app.controller('primaryctrl', ctrls.primaryctrl); app.controller('secondaryctrl', ctrls.secondaryctrl); 

and

<div ng-controller="primaryctrl primary">     <p ng-repeat="item in primary.items">{{item}}</p> </div>  <div ng-controller="secondaryctrl secondary">     <p ng-repeat="item in secondary.items">{{item}}</p> </div> 

you may check angular classy, brings opinionated viable extending syntax angular.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -