我刚开始使用 Angular,实现起来似乎不错。
我总是使用 ng-model
从 textfield
获取文本。
我可以借助 ng-model
或其他工具获取按钮文本吗?
我知道在这里问不是个好问题。但我在任何地方都没有得到任何相关的解决方案。
例如这是按钮
<button class="common btnDarkGrey">Do it</button>
我想用 Angular Do it
谢谢。
最佳答案
您应该使用 ng-bind
将 Controller 中的数据绑定(bind)到按钮。
<button ng-bind="buttonNameVariable"></button>
然后在你的 Controller 中你将有一个名为 scope.buttonNameVariable="Do it"
您可以在 Controller 中使用变量,并通过变量检索它。您仅将 ng-model 用于 html 中的输入字段,而不用于例如按钮。
关于javascript - 如何在 angular.js 中使用 ng-model 获取按钮文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27835358/