为什么$ scope.data.task是未定义的?

时间:2019-06-06 22:36:19

标签: angularjs scope

我可以选择一个角度函数。但是当我重新加载页面(f5)时,$ scope.data.tasks是未定义的 这是我的html

<div class="col-sm-3">
<label>
<select class="w-full form-control col-sm-10" ng-model="data.category"  ng-options="cantTasksByCat(category) for category in categoriesEx  | orderBy:'title'" ></select>
</label>
</div>

这是我的js

app.controller('TasksCtrl', ['$scope',  'api', 'toaster', function($scope, api, toaster, ) {
   $scope.data = {
  tasks: [],
  category: tempCat,
  selectedTask: null

};
$scope.data.tasks = $scope.tasks;

$scope.cantTasksByCat = function (cat) {
  let cantTasksByCategory;
  if (cat.title.en==='View all'){
    cantTasksByCategory= $scope.tasks;
    return " (" + cantTasksByCategory.length + ")";
  }  
  cantTasksByCategory = $scope.tasks.filter(function(obj) {
    return obj.category.objectId== cat.objectId;
});
  return " (" + cantTasksByCategory.length + ")"; };}]);

我要加载 enter image description here

选择正确填满,但是当我重新加载浏览器(f5)时,它标志我错误。 $ Scope.data.tasks是未定义的。就像尚未能够获得请求一样

0 个答案:

没有答案