我正在尝试将 html 附加到页面上的第一个 h1 之后。 angular.element 返回 h1 元素,但它没有附加文本“hello!”在 h1 元素之后。尽量避免使用完整的 JQuery。有人有想法吗?
app.controller('Test', ['$scope', function ($scope) {
var h1 = angular.element(document).find("h1").length > 0 ? angular.element(document).find("h1")[0] : null
if (h1 != null) {
angular.element(h1).after(function () {
return "hello!"
})
}
}]);
最佳答案
不要在 after
中传递函数,只需包含所需的文本作为参数即可。
if (h1 != null) {
angular.element(h1).after('Hello')
}
关于javascript - 在 AngularJS 中使用 jqLite 附加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37699741/