当前位置:首页>开发>正文

如何用angular插入一段html angularjs怎么增加元素

2023-06-28 00:32:24 互联网 未知 开发

 如何用angular插入一段html angularjs怎么增加元素

如何用angular插入一段html

可以用$complie服务,它的作用是动态编译的。
var el=$compile("HTML代码")(scope)
element.append(el) //element是插入带的容器

angularjs怎么增加元素

//通过$compile动态编译htmlvar html="

我是后添加的
"

var template = angular.element(html)
var mobileDialogElement = $compile(template)($scope)
angular.element("#" id).append(mobileDialogElement) // remove移除创建的元素

var closeMobileDialog = function () {
if (mobileDialogElement) {  
mobileDialogElement.remove()
}

angularjs怎么发异步请求

使用AngularJS向同一个URL发送POST请求,同时带上一些POST数据,你可以像下面这样做:
var postData = {text:long blob of text}
//下面这一行会被当成参数附加到URL后面,所以post请求最终会变成/api/user?id=var config = {params: {id: 5}}
$http.post(api/user, postData, config
).success(function(data, status, headers, config) {
//成功之后做一些事情
}).error(function(data, status, headers, config) {
//处理错误
})

最新文章