我正在开发AngularJS应用。我的应用程序有一个插件,可以在这里看到。这个应用程式提供了我为另一个专案所提供的服务。该服务如下所示:
myApp.service('myService', ['$http', '$timeout', '$q', function($http, $timeout, $q) {
this.getResults = function() {
var deferred = $q.defer();
var results = [];
results.push({ name: 'Alpha', id:1, description:'The first' });
results.push({ name: 'Bravo', id:2, description:'The second' });
results.push({ name: 'Charlie', id:3, description:'The third' });
deferred.resolve(results);
return deferred.promise;
};
我正在尝试在UI Bootstrap框架中使用Typeahead控件。我已经成功地整理了基础知识。但是,我无法弄清楚如何使自定义结果模板起作用。我不知道他们从哪里提取属性值。我只是试图创建一个显示名称和描述字段的模板。选择该项目后,我想在文本框中显示名称。我的朋克在这里。
请在这里查看http://plnkr.co/edit/VJFx436Tsew9unXWNQsJ?p=preview
1.在这里设置模板名称,typeahead-template-url="result.html"
因此模板脚本的ID必须为"result.html"
要从模板中的匹配模型访问数据,您需要使用match.model
前缀。
<script type="text/ng-template" id="result.html">
<a>
<div><h6>{{match.model.name}}<h6>< /div>
<div><p>{{match.model.description}}</p></div>
</a>
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句