角度渲染问题

时间:2015-08-27 20:00:41

标签: javascript angularjs

我尝试创建一个类似于Google角色的搜索栏。如果用户点击它,它工作正常,但如果用户选中它,下拉菜单将不会呈现。导致这种行为差异的原因是什么?

SearchCtrl.js

(function(){

var SearchCtrl = function(SearchService){       
    this.results = [];

    this.getResults = function(query){
        if (!query) { return; }
        SearchService.getResults(query)
        .then(function(results){                
            this.results = results.plain();
        }.bind(this));
    };
};

angular.module('myApp')
.controller('SearchCtrl', SearchCtrl);
})();

search.html

<li class="search-box visible-md visible-lg dropdown open">
    <div class="input-group">
        <span class="input-group-addon"><i class="ti-search text-muted"></i></span>
        <input 
        type="text" 
        class="form-control dropdown-toggle" 
        ng-model="sc.query"
        ng-change="sc.getResults(sc.query)"
        placeholder="Search...">
    </div>

    <ul class="dropdown-menu with-arrow panel panel-default" ng-if="sc.results.length">
        <li ng-repeat="result in sc.results">
            <a href="/results/{{result.id}}">
                <i></i>
                <span>{{result.name}}</span>
            </a>
        </li>
    </ul>
</li>

0 个答案:

没有答案