how to fix my code?? angularjs, ejs code

微笑、不失礼 提交于 2019-12-12 23:52:20

问题


I used angular js and ejs. Repeat is good but, Database data does not come in.

How should I fix my code?

In this angularjs code

var app = angular.module('myApp', []);
app.controller('BasicCtrl20', function($scope, $http) {
  $http.get("/concept_db")
  .then(function(response) {
      $scope.gridOptions4 = response.data;

  });

});

In this my code

<div class="container">
  <div ng-app="myApp" ng-controller="BasicCtrl20"> 
   <div class="row">
<span style="line-height:30px"><br></span>

<div class="toggles">
   <button id="showall">전체 제품 보기</button> 
  <button id="furniture">가구/인테리어</button>
  <button id="homeappliances">디지털 가전</button>
  <button id="life">생활/건강</button>
  <button id="sport">스포츠/레저</button>
  <button id="delivery">출산/육아</button>
  <button id="fashion">패션잡화</button>
</div>

<div class="posts">
    <div class="gallery">
        <div ng-repeat="gridoptions in gridOptions4">
            <div class="{{gridOptions.class}}">
                <div class="gallery-item">
                    <a href="{{gridOptions.main_href}}">
                        <div class="gallery-item-image">
                            <img ng-src="{{gridOptions.imgsrc}}">
                        </div>
                    </a>
                    <div class="gallery-item-description">
                        <p align="center">{{gridOptions.name}}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>

and reuslt

I want to import data from the database.

console log result


回答1:


You have a bunch of elements, so there is clearly something there. ng-repeat does not create 20 elements from an error or thin air.

But the field name is probably wrong. It is not name (or name is actually empty on every item in the database!). Check that you got the field name right. Maybe its upper case Name or NAME or mispellt naem. Or something completely different like label or title.

the easy thing to do is to log the data when you get it, and see for yourself.

.then(function(response) {
    console.log( response.data );  <-- look in the console!
    scope.gridOptions4 = response.data; 

Or since it's a GET-request. Right-click that link in your console XHR finished loading: GET "https://localhost:3000/concept_db". <-- Right-click, open in a new tab. It might not be the most easy thing to read, but it's a such a quick thing to just take a peek at data so you know what you are working with.



来源:https://stackoverflow.com/questions/50634553/how-to-fix-my-code-angularjs-ejs-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!