ReferenceError: newFunction не определена - PullRequest
0 голосов
/ 11 мая 2018

Как определить новую функцию в угловых, может кто-нибудь, пожалуйста, помогите мне Мой код такой:

var app = angular.module('rtsApp', ['ngMaterial', 'ngMessages', 'ngStorage','ngRoute', 'restangular','timepickerPop', 'ngStomp', 'ngCookies', 'angular-cron-gen','uiSwitch','ngMaterial', 'md.data.table']);

app.config(function(RestangularProvider) {
    newFunction(RestangularProvider);//I need newFunction here
    RestangularProvider.setDefaultHeaders({
        "X-API-KEY": "sks@2017",
        "Content-Type": "application/json"

    });

На самом деле я получаю эту ошибку

Не удалось создать экземпляр модуля rtsApp из-за:

ReferenceError: newFunction не определена

at http://localhost:3000/dist/js/scripts.min.js:1738:5
at Object.invoke (http://localhost:3000/dist/js/vendor.min.js:82:460)
at d (http://localhost:3000/dist/js/vendor.min.js:80:333)
at http://localhost:3000/dist/js/vendor.min.js:80:472
at q (http://localhost:3000/dist/js/vendor.min.js:46:7)
at g (http://localhost:3000/dist/js/vendor.min.js:80:234)
at gb (http://localhost:3000/dist/js/vendor.min.js:84:352)
at c (http://localhost:3000/dist/js/vendor.min.js:60:57)
at Wc (http://localhost:3000/dist/js/vendor.min.js:60:370)
at ye (http://localhost:3000/dist/js/vendor.min.js:59:45)

Ответы [ 2 ]

0 голосов
/ 11 мая 2018

попробуйте: - другой сценарий - следующий код,

'use strict';
var deck = angular.module('app',
        ['ui.router',other lib...]);

angular.module("app").config(["$breadcrumbProvider", "$httpProvider", function ($breadcrumbProvider, $httpProvider) {
        $breadcrumbProvider.setOptions({
            prefixStateName: 'userHome.main',
            template: 'bootstrap3'
        });
        //Do No Remove This Line 
        $httpProvider.defaults.withCredentials = true;
    }]);
0 голосов
/ 11 мая 2018

Создайте файл и определите модуль в файле.Например, создайте globalFunctions.js и добавьте этот файл в ваш index.html файл со следующим:

<script src="/path/to/file/location/globalFunctions.js"></script>

Определите модуль, а также ваши глобальные функции.как это:

(function () {
    angular.module('test', []);
})();

function test() {
    console.log("test");
}

Вставить его в основное приложение (app.module.js) и вызвать его:

(function() {
  'use strict';
  var app = angular.module('app', [
    'test',
     ...
  ]);

  app.config(function($routeProvider, $locationProvider) {
    test();
  });
})();

Обновление

Все файлы для простого теста:

app.module.js

(function () {
  var app = angular.module('app', [
    'ngRoute',
    'global'
  ]);

  app.config(function ($routeProvider, $locationProvider) {
    test();
  });

})();

test.module.js

(function () {
    angular.module('global', []);
})();

function test() {
    console.log("it is test function here");
}

index.html

<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://code.angularjs.org/1.2.16/angular-route.min.js"></script>
<script src="app.module.js"></script>
<script src="test.module.js"></script>

<body ng-app="app">
  <h2>It is a test</h2>
</body>
</html>

Это Плункер предусмотрено для моего решения

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...