angularjs - 如何使用 ui-mention angularjs 库设置默认提及?

标签 angularjs angularjs-directive

关于如何使用 ui-mention angularjs 库 ( https://github.com/angular-ui/ui-mention ) 设置默认提及的任何想法?例如,在文本区域中始终有两个默认提及(bob baker 和 Kenny Logins),如附图所示
enter image description here

谢谢你的帮助,伙计们。

最佳答案

通过添加一些用户提及,您将在底部看到相关的模型:

ng-model (post.message): "hi there @[bob barker:11123]"

所以对于你的例子,初始化它就像:
$rootScope.post = {
    message: "hi there @[bob barker:11123] @[kenny logins:123ab-123]"
};

但是你会注意到它不起作用。
查看代码后,如果您能够在 $mention.mentions 中添加这些用户,它将起作用。因为$mentioncontrollerAs在 uiMention 指令中,您可以通过 uiMention.mentions 在自定义指令(示例中的mentionExample)中设置它.
所以通过添加:
uiMentions.mentions = uiMention.mentions.push(choices[0]); //bob barker
uiMentions.mentions = uiMention.mentions.push(choices[1]); //kenny logins

function link在mentionExample 中,这会起作用。

但我认为你应该通过在 $scope.post.message 中搜索所有 @mentions 然后在 uiMentions.mentions 中添加相关的用户项来动态地(在这个链接函数中)。

看看我为您创建的这个 plunker:http://embed.plnkr.co/o3mByKttPthpiqe4O5x6/

关于angularjs - 如何使用 ui-mention angularjs 库设置默认提及?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45004185/

相关文章:

css - Angularjs 显示/隐藏和交替样式

javascript - 与另一个指令一起使用时,angularjs 验证器不起作用

javascript - 如何在angularjs工厂中调用函数

javascript - 替换值时 AngularJS View 不更新

javascript - 如何在指令上测试 Angular $destroy 事件?

javascript - 除非刷新,否则 Firebase 数据不会加载到列表中(AngularJS、Firebase 和 ionic)

javascript - 变量不使用 ng-bind 呈现

javascript - href 中的 Angular 绑定(bind)有效但 src 绑定(bind)无效?

javascript - 使用angularJS手动引导时如何共享$rootScope?

javascript - 为什么这个 Angular 选择包装器指令不起作用?