• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

question-closed W AngularJs: Argument 'fn' is not a function, got string

Object Storage Arubacloud
0 głosów
154 wizyt
pytanie zadane 26 marca 2019 w JavaScript przez Franek Kimono Początkujący (340 p.)
zamknięte 26 marca 2019 przez ScriptyChris
Cześć Panowie 
Debugger w DevTools nie chce wejść głebiej niż linijka: .config('$stateProvider', [function ($stateProvider) {

natomiast w drugim plik nie wchodzi głebiej niż:  .controller('SubscriptiontListController',[function () { 



angular
    .module('jswSubscription', ['ui.router'])
    .config('$stateProvider', [function ($stateProvider) {
        debugger

        $stateProvider.state({
            name: 'list',
            url: '/list/{id}',
            params: { 'id': '' },
            templateUrl: './Areas/Subscription/Scripts/templates/_list.html',
            controller: 'SubscriptiontListController as $ctrl',
            clearHistory: true
        });      
    }]);

 

angular
    .module('jswSubscription')
    .controller('SubscriptiontListController',[function () {
       

        debugger
    	
    }]);

To mam w _Layout.cshtml

 <script type="text/javascript">
    @(
        Html.AngularModule("jswApp")
        .WithDependantModules("jswSubscription")
            .WithDependantModules("ui.router")
            .WithDependantModulesFromViewBag()
            .Generate()
    )
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JSW.WebSite.Helpers
{
    public static class AngularHelper
    {
        public static AngularModuleFluentApi AngularModule(this HtmlHelper htmlHelper, string moduleName) //notka ten helper jest dla dołaczenia modułow w vidoku
        {
            return new AngularModuleFluentApi(htmlHelper, moduleName);
        }
    }

    public class AngularModuleFluentApi
    {
        private HtmlHelper htmlHelper;
        private string moduleName;
        private List<string> dependencies = new List<string>();

        public IHtmlString Generate()
        {
            var dependenciesContent = string.Join(", ", this.dependencies.Distinct().Select(d => $"'{d}'"));
            var content = $"var {moduleName} = angular.module('{moduleName}', [{dependenciesContent}]);";
            return new MvcHtmlString(content);
        }       

        public AngularModuleFluentApi(HtmlHelper htmlHelper, string moduleName)
        {
            this.htmlHelper = htmlHelper;
            this.moduleName = moduleName;
        }

        public AngularModuleFluentApi WithDependantModules(params string[] dependencies)
        {
            this.dependencies.AddRange(dependencies);
            return this;
        }

        public AngularModuleFluentApi WithDependantModulesFromViewBag()
        {
            var angularModules = htmlHelper.ViewBag.AngularModules as string;
            if (!string.IsNullOrEmpty(angularModules))
            {
                var angularModuleNames = angularModules.Split(';');
                return WithDependantModules(angularModuleNames);
            }

            return this;
        }      
    }
}

Taka jest treść błedu:

angular.js:138 Uncaught Error: [$injector:modulerr] Failed to instantiate module jswApp due to:
Error: [$injector:modulerr] Failed to instantiate module jswSubscription due to:
Error: [ng:areq] Argument 'fn' is not a function, got string


https://errors.angularjs.org/1.7.8/$injector/modulerr?p0=jswApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20Failed%20to%20instantiate%20module%20jswSubscription%20due%20to%3A%0AError%3A%20%5Bng%3Aareq%5D%20Argument%20'fn'%20is%20not%20a%20function%2C%20got%20string%0A%0Ahttps%3A%2F%2Ferrors.angularjs.org%2F1.7.8%2F%24injector%2Fmodulerr%3Fp0%3DjswSubscription%26p1%3DError%253A%2520%255Bng%253Aareq%255D%2520Argument%2520'fn'%2520is%2520not%2520a%2520function%252C%2520got%2520string%250Ahttps%253A%252F%252Ferrors.angularjs.org%252F1.7.8%252Fng%252Fareq%253Fp0%253Dfn%2526p1%253Dnot%252520a%252520function%25252C%252520got%252520string%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A138%253A12%250A%2520%2520%2520%2520at%2520assertArg%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A2094%253A11)%250A%2520%2520%2520%2520at%2520assertArgFn%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A2104%253A3)%250A%2520%2520%2520%2520at%2520Function.annotate%2520%255Bas%2520%2524%2524annotate%255D%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A4320%253A5)%250A%2520%2520%2520%2520at%2520injectionArgs%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A5100%253A36)%250A%2520%2520%2520%2520at%2520Object.invoke%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A5133%253A18)%250A%2520%2520%2520%2520at%2520runInvokeQueue%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A5030%253A35)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A5040%253A11%250A%2520%2520%2520%2520at%2520forEach%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A387%253A20)%250A%2520%2520%2520%2520at%2520loadModules%2520(http%253A%252F%252Flocalhost%253A55765%252FContent%252Fvendor%252Fangular%252Fangular.js%253A5020%253A5)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A138%3A12%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A5060%3A15%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A387%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A5020%3A5)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A5038%3A40%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A387%3A20)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A5020%3A5)%0A%20%20%20%20at%20createInjector%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A4937%3A19)%0A%20%20%20%20at%20doBootstrap%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A1960%3A20)%0A%20%20%20%20at%20bootstrap%20(http%3A%2F%2Flocalhost%3A55765%2FContent%2Fvendor%2Fangular%2Fangular.js%3A1981%3A12)
    at angular.js:138
    at angular.js:5060
    at forEach (angular.js:387)
    at loadModules (angular.js:5020)
    at createInjector (angular.js:4937)
    at doBootstrap (angular.js:1960)
    at bootstrap (angular.js:1981)
    at angularInit (angular.js:1866)
    at angular.js:36430
    at HTMLDocument.trigger (angular.js:3520)

komentarz zamknięcia: Problem rozwiązany.
1
komentarz 26 marca 2019 przez ScriptyChris Mędrzec (190,190 p.)

Error: [ng:areq] Argument 'fn' is not a function, got string

Włącz pauzowanie kodu na wyjątku i zobacz, o który argument chodzi.

komentarz 26 marca 2019 przez Franek Kimono Początkujący (340 p.)

@Franek Kimono,  Dziękuję  JSHolic nie wiedziałem że tak można. Już znalazłem problem to byłą pospolity bład składni, powinno być w module: .config(['$stateProvider'

Podobne pytania

0 głosów
1 odpowiedź 270 wizyt
pytanie zadane 2 czerwca 2023 w JavaScript przez DzikieHarce Użytkownik (690 p.)
0 głosów
1 odpowiedź 555 wizyt
0 głosów
2 odpowiedzi 516 wizyt
pytanie zadane 6 września 2021 w JavaScript przez Maxxxii Obywatel (1,260 p.)

92,573 zapytań

141,423 odpowiedzi

319,645 komentarzy

61,959 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...