对象的角度回调问题

时间:2017-05-23 10:50:22

标签: javascript angularjs

我有2个API调用,提供2个JSON数组。控制器写为: -

<div class="container">
<div>
<h1>Reports</h1>
<tr ng-repeat="a in $ctrl.Details">
  <th><h4>UI Url: <a>{{a.url}}</a></h4></th>
  <th><h4>Host IP: {{a.IP}}</h3></th>
  <th><h4>Release: {{a.mode}}</h3></th>
</tr>
</div>
<div>
<table class="table table-bordered table-hover data-filter-control="true" " >
  <thead>
    <tr>
      <th>#</th>
      <th>Screen ID</th>
      <th>Mast ID</th>
      <th>Description</th>
      <th data-filter-control="select">Result</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="result in $ctrl.report">
      <th></th>
      <th>{{result.ScreenID}}</th>
      <th><a href="#!/reports/{{result._id}}">{{result.MastID}}</a></th>
      <th>{{result.Description}}</th>
      <th><span ng-class="{
          'color-red': result.result === 'Failed',
          'color-green': result.result === 'Passed'}">{{result.result}}
  </span></th>
    </tr>
  </tbody>
 </table>
 </div>
 </div>

模板文件使用以下详细信息: -

factory('Rep', ['$http',
function($http) {
  return {
    repGetByCurDate : repGetByCurDate
    envGetSingle: envGetSingle
  };

  function envGetSingle(envName) {
    return $http.get('/api/envs/currDate/' + envName + '/envDetails').then(complete).catch(failed);
  }

  function repGetByCurDate(envName) {
    return $http.get('/api/envs/currDate/' + envName).then(complete).catch(failed);
  }

  function complete(response) {
    return response;
  }

  function failed(error) {
    console.log(error.statusText);
  }
}

工厂代表定义为: -

<IfModule mod_rewrite.c>
    RewriteBase /
    RewriteEngine on
    # Uncomment if you have a .well-known directory in the app folder, e.g. for the Let's Encrypt challenge
    # https://tools.ietf.org/html/rfc5785
    #RewriteRule ^(\.well-known/.*)$ $1 [L]
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
</IfModule>

])

工厂返回适当的数据。当我尝试访问角度模板文件中的self.Details时,会出现问题。 self.report有值但是self.Details是空的。我如何在self.Details中坚持对象?

1 个答案:

答案 0 :(得分:0)

结果Details变量是数组中的单个元素。因此,要访问它,我们在模板文件中使用[0] .url而不是a。这解决了这个问题。