Base solution for your next web application
Open Closed

angularjs, success is not a function error #2675


User avatar
0
billalayub created

Hi, I started developing a new module in ASPNetZero AngularJs by reading aspnetzero.com step by step development guide for ASP.NET MVC 5.x & Angularjs 1.x and I got error success is not a function error in DevTool by chrome.

Attached are error, code of index.js and index.cshtml:

Error: Registered to the SignalR server! angular.min.js:122 TypeError: employeeService.getEmployees(...).success is not a function at new <anonymous> (<a class="postlink" href="http://localhost:6240/App/tenant/views/hrm/employees/index.js:9:46">http://localhost:6240/App/tenant/views/ ... ex.js:9:46</a>) at Object.invoke (<a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:43:171">http://localhost:6240/Scripts/angular.min.js:43:171</a>) at R.instance (<a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:93:35">http://localhost:6240/Scripts/angular.min.js:93:35</a>) at n (<a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:68:42">http://localhost:6240/Scripts/angular.min.js:68:42</a>) at g (<a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:60:496">http://localhost:6240/Scripts/angular.min.js:60:496</a>) at <a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:60:119">http://localhost:6240/Scripts/angular.min.js:60:119</a> at Object.<anonymous> (<a class="postlink" href="http://localhost:6240/Scripts/angular-ui-router.min.js:7:24965">http://localhost:6240/Scripts/angular-u ... js:7:24965</a>) at <a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:16:71">http://localhost:6240/Scripts/angular.min.js:16:71</a> at ta (<a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:84:35">http://localhost:6240/Scripts/angular.min.js:84:35</a>) at n (<a class="postlink" href="http://localhost:6240/Scripts/angular.min.js:69:226">http://localhost:6240/Scripts/angular.min.js:69:226</a>) <div ui-view="" class="fade-in-up ng-scope"> (anonymous) @ angular.min.js:122

index.js: (function () { appModule.controller('tenant.views.hrm.employees.index', [ '$scope', 'abp.services.app.employees', function ($scope, employeeService) { var vm = this;

        vm.employees = [];

        employeeService.getEmployees({}).success(function (result) {
            vm.employees = result.items;
        });

    }
]);

})();

index.cshtml: <div ng-controller="tenant.views.hrm.employees.index as vm"> <div class="row margin-bottom-5"> <div class="col-xs-12"> <div class="page-head"> <div class="page-title"> <h1> <span>@L("Employees")</span> </h1> </div> </div> </div> </div> <div class="portlet light"> <div class="portlet-body">

        &lt;h3&gt;@L("AllEmployees")&lt;/h3&gt;

        &lt;div class=&quot;list-group&quot;&gt;
            &lt;a href=&quot;javascript:;&quot; class=&quot;list-group-item&quot; ng-repeat=&quot;employee in vm.employees&quot;&gt;
                &lt;h4 class=&quot;list-group-item-heading&quot;&gt;
                    {{employee.name}} {{employee.surname}}
                &lt;/h4&gt;
                &lt;p class=&quot;list-group-item-text&quot;&gt;
                    {{employee.emailAddress}}
                &lt;/p&gt;
            &lt;/a&gt;
        &lt;/div&gt;

    &lt;/div&gt;
&lt;/div&gt;

</div>

Whats wrong with it???


5 Answer(s)
  • User Avatar
    0
    bilalhaidar created

    Hi Bilal,

    You need to use something like this:

    employeeService.getEmployees({}).then(function (result) {
    vm.employees = result.items;
    });
    

    You can also add .finally() function in case you want for example to signal loading is done.

    Hope this helps, Bilal

  • User Avatar
    0
    billalayub created

    Bilal, I tried this but It is not working for me. This code does not prompt any error but not populating vm.employess array.

    Please help me, I am very new to AngularJs.

    Thanks in advance!!!

    Regards,

    Bilal

  • User Avatar
    0
    bilalhaidar created

    Hi Bilal, We need to see more code to see how you are returning data from server.

    But one thing I noticed, is the "result.items". Maybe it should be "result.data.items".

    Bilal

  • User Avatar
    0
    billalayub created

    <cite>drcgreece: </cite> Hi Bilal, We need to see more code to see how you are returning data from server.

    But one thing I noticed, is the "result.items". Maybe it should be "result.data.items".

    Bilal

    Thank you Bilal, its working now! :D

  • User Avatar
    0
    bilalhaidar created

    I am glad it is working now.

    This framework is amazing, but it might need some time digging into the source code and with time you get to learn many things out of it.

    Always pass by and ask your questions.

    Bilal