关于如何使用 ui-mention angularjs 库 ( https://github.com/angular-ui/ui-mention ) 设置默认提及的任何想法?例如,在文本区域中始终有两个默认提及(bob baker 和 Kenny Logins),如附图所示
谢谢你的帮助,伙计们。
最佳答案
通过添加一些用户提及,您将在底部看到相关的模型:
ng-model (post.message): "hi there @[bob barker:11123]"
所以对于你的例子,初始化它就像:
$rootScope.post = {
message: "hi there @[bob barker:11123] @[kenny logins:123ab-123]"
};
但是你会注意到它不起作用。
查看代码后,如果您能够在
$mention.mentions
中添加这些用户,它将起作用。因为$mention
是 controllerAs
在 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/