首页 > 解决方案 > Angular JS, JSON via extern Libary Function not storing in $scope

问题描述

Hey People i have a problem storing my JSON in the $scope. this is the Code:

  var app = angular.module("mainApp",[]);

  app.service("KategorienService", function() {
    this.getKategorien = function() {
      return Workbook.load(optionsStatus)
    };
  });

  app.controller("KategorienCtrl", function($scope, KategorienService) {
    KategorienService.getKategorien().then(res => {
      $scope.Kategorien = res;
    });
  });

The Workbook.load() returns a Promise with a parsed JSON Object. Now i try to Copy the JSON who is already parsed into the Scope and display it via ng-repeeat like so:

  <div ng-app="mainApp">
    <div ng-controller="KategorienCtrl">
      <p>Kategorien: </p>
      <li ng-repeat="Kategorie in Kategorien" >
        {{Kategorie.label + Kategorie.value}}
      </li>
    </div>
  </div>

But nothing is show, even tho the Console shows that the $scope.Katogrien has the JSON. this is the JSON:

(2) [{…}, {…}]
0:
label: "Fusball"
value: "FUS"
_autoId: 3
_created: {$date: "2021-09-03T08:41:20.613Z"}
_deviceId: "c4IDr2tLTmG6MOQKTMfyRd"
_id: {$oid: "6131dfcbe4b055b5d3b86788"}
_lastModified: {$date: "2021-09-03T08:41:47.038Z"}
_sheet: "6131df7ae4b055b5d3b86775"
_userProfile: ""
[[Prototype]]: Object
1: {_id: {…}, value: "HAND", label: "Handball", _user: "Jayklops", _userProfile: "", …}
length: 2

pls Help best regards

标签: javascriptangularjs

解决方案


推荐阅读