angular.js - 执行顺序问题,angular需要后台拿到数据后编译directive
高洛峰
高洛峰 2017-05-15 17:12:25
0
3
696

打开一个页面,需要先发起一个$http请求从后台拿到数据,然后将数据的某几个字段作为参数传递给directive中去编译。

现在问题是页面一打开好像就执行directive中的代码了。因为数据还没有拿到,会报错。如何调整?

已尝试并成功:先拿代码数据然后使用$compile去动态编译directive然后append到dom中。
想了解其他好的方法。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
曾经蜡笔没有小新

1. You can use Promise to encapsulate the AJAX request, and then perform subsequent operations after receiving the result in the instruction.
2. You can directly use $watch in the instruction to check whether the correct data is returned, and then perform subsequent operations. However, it is recommended that $watch is only used to check the data update status and not perform other operations.

为情所困

It’s not clear what your requirements are. You just described a directive value-passing compilation problem

伊谢尔伦

Tell us how to bind the data object to the DOM, use the instruction to get the data on the DOM, and then request the data in the controller

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!