ng-click上的角度范围,ng-repeat和调用方法

时间:2013-07-19 01:16:03

标签: button twitter-bootstrap angularjs angularjs-scope

我是一名自学新手编程,致力于使用node,angular,bootstrap和图形数据库neo4j开发Web应用程序。

我希望在下面的代码中找到我错误的内容。

HTML破解:

<div class='btn-group'  ng-controller="typeCtrl" ng-repeat="type in display">
<button class='btn' ng-click='whatsmyname(type)' > {{type}}</button>
    <button class='btn dropdown-toggle dropdown'><span class='caret'></span></button>
<ul class= 'dropdown-menu'>
  <li><a>Exclue Term</a></li>
  <li><a>Exclue and Load</a></li>
  <li><a>Include</a></li>
  <li><a>Include and Load</a></li>
</ul>
<p>Hello? {{display}}</p>

角度控制器:

function typeCtrl($scope){
    var theList = [];
    var alltheterms;
    var things = [{"name":"Image","tags":["Type","Image","Core"]},{"name":"GIF","tags":["Type","Image"]},{"name":"Infographic","tags":["Type","Image"]},{"name":"Chart","tags":["Type","Image"]},{"name":"Photo","tags":["Type","Image"]},{"name":"Microscope","tags":["Type","Image"]},{"name":"Telescope","tags":["Type","Image"]},{"name":"Text","tags":["Type","Text","Core"]},{"name":"Article","tags":["Type","Text"]},{"name":"Short Story","tags":["Type","Text"]},{"name":"Quote","tags":["Type","Text"]},{"name":"Podcast","tags":["Type","Audio"]},{"name":"Audio","tags":["Type","Audio","Core"]},{"name":"Video","tags":["Type","Video","Core"]},{"name":"Map","tags":["Type","Image"]},{"name":"Website","tags":["Type","Core","Website"]}];
    var core = [];

    var filterData = function(data){
             for(var i=0;i<data.length;i++){
                 if (data[i].tags.indexOf("Core") > -1){
                     theList.push(data[i].name);
                 }
             }
             alltheterms = data;
             core = theList
             $scope.display = theList;
         };

 $scope.whatsmyname = function (value){
        $scope.value = value;
        theList = [];
        for(var i=0;i<alltheterms.length;i++){
            if (alltheterms[i].tags.indexOf(value) > -1){
                theList.push(alltheterms[i].name);
            }
        }
        var notAgain = theList.indexOf(value);
        theList.splice(notAgain,1);
        $scope.display=theList;
    };   
    $scope.reset = function(){
      $scope.display = core;
    }
  filterData(things);

}

Link to Plunker

我很困惑为什么简单的例子调用函数而更复杂的例子没有。请注意,在我的机器上,复杂的示例至少显示正确 - 我必须在将其转换为plunker时出错。据我所知,这可能与范围有关,但我无法确定究竟发生了什么。任何建议(与此问题直接相关以及一般建议)都将不胜感激。

0 个答案:

没有答案