Angular JS ng-repeat不能按预期工作

时间:2017-02-09 05:14:43

标签: javascript angularjs angularjs-directive angularjs-ng-repeat

我有一个像这样的控制器:

controller('BreadCrumbs', ['$scope','crumble','$rootScope', function ($scope,crumble,$rootScope) {    
    function init (){
        $scope.ui={};
        $scope.ui.mdBreadCrumbs=[{"path":"path1","label":"label1"}];     
        $rootScope.oldScope=$scope;
    }
    $scope.setBreadCrumbs=function() {        
        $scope.ui.mdBreadCrumbs=crumble.trail;    
    } 
    init();
}]);

和HTML,

<ol id="breadCrumbList"  ng-controller="BreadCrumbs as bcrmbs">
 {{ui.mdBreadCrumbs}}
  <li ng-repeat="bc in ui.mdBreadCrumbs">
    <a ng-href="{{bc.path}}">{{bc.label}}</a>
  </li>
</ol>

{{ui.mdBreadCrumbs}}显示的内容有点[{"path":"path1","label":"label1"}]。 但是在ng-repeat中,它不是迭代的。 使用$scope.setBreadCrumbs我添加了一些值,但仍然无法使用ngRepeat。

任何人都知道它为什么不起作用?

2 个答案:

答案 0 :(得分:0)

更改

<ol id="breadCrumbList"  ng-controller="BreadCrumbs">

var app = angular.module('app', []);
app.controller('BreadCrumbs', ['$scope', function($scope) {
  $scope.ui = {};
  $scope.ui.mdBreadCrumbs = [{
    "path": "path1",
    "label": "label1"
  }];
}]);

<强>样本

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title></title>
</head>

<body ng-app="app" ng-controller="BreadCrumbs">
  <ol id="breadCrumbList">
 {{ui.mdBreadCrumbs}}
  <li ng-repeat="bc in ui.mdBreadCrumbs">
    <a ng-href="{{bc.path}}">{{bc.label}}</a>
  </li>
</ol>
  <script type=" text/javascript " src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js "></script>
  <script type="text/javascript " src="MainViewController.js "></script>
</body>
</html>
DataFrame

答案 1 :(得分:0)

您必须在HTML中更改某些内容,并且您的HTML应如下所示:

// helpers/debug-filter.js
export function debugFilter([value]) {
  return Ember.typeOf(value) !== 'function';
}

export default Ember.Helper.helper(formatCurrency);