Çoklu denetleyicileri olan bir açısal modül için $ kapsamını nasıl oluştururum? Şu anda, aşağıdaki hata iletisi alıyorum:
Error: [$injector:modulerr] Failed to instantiate module hello due to:
[$injector:modulerr] Failed to instantiate module navigation due to:
[$injector:modulerr] Failed to instantiate module $scope due to:
[$injector:nomod] Module '$scope' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
şöyle uygulamanın yapısı şöyledir:
'use strict';
/** * Main module of the application. */
angular
.module('hello', ['ngAnimate', 'ngRoute', 'ngTouch', 'auth', 'home',
'secure', 'public1', 'navigation', 'ui.bootstrap' ])
.config(function ($routeProvider, $httpProvider, $locationProvider) {
//a bunch of config stuff like routeProvider, etc.
})
.run(['$cookies', function($cookies) {
//some startup stuff like setting default values for cookies, etc.
}]);
navigation.js
olarak tanımlanır:
hello
modül olarak tanımlanır:
'use strict';
angular
.module('navigation', ['$scope', 'auth', 'modalService', 'ngRoute', 'ngAnimate', 'ui.bootstrap'])
.controller('navigation', function($scope, auth, modalService, $route, $uibModal) {
// code for various stuff,
// including code calling the second controller below
$scope.someVariable = 'some value';
});
// Please note that $uibModalInstance represents a modal window (instance) dependency.
// It is not the same as the $uibModal service used above.
angular.module('navigation', ['$scope', '$uibModalInstance', 'items'])
.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance, items) {
//code that is controlled by code from the preceding controller
$scope.someOtherVariable = 'some other value';
});
Not
'$scope' is not defined.
Sadece açısal 'modül' sadece önyükleme uygulaması sırasında DI dizi içinde enjekte edilebilir .. mümkün değil $ kapsam bağımlılığı enjekte edilir .. $ kapsam sadece içinde kullanılabilir denetleyici ve yönerge bağlantı işlevi –
, bağımlılık olmadığından $ kapsamı enjekte edemezsiniz. Kapsam, denetleyici içinde kullanılabilmesi için açısal olarak verilir. – Rishab777
@PankajParkar Tamam, peki o zaman işe almak için OP'deki kodu nasıl değiştirebilirim? Sadece bir örneklemdeki kodu denemek istiyorum, böylece onu diğer konfigürasyonlara taşıyabilirim. – CodeMed