Input text box, generate li element, and li element can bind events
漂亮男人2017-05-15 16:55:10
In fact, this is a problem that may become very complicated. In reality, there are many solutions. I will write you the simplest reference:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Then in the corresponding template:
1 2 3 4 5 6 7 8 9 10 11 |
|
This is an idea. There are too many variable factors in reality, so it’s hard to go into details one by one. The key points to consider when dealing with similar problems are pretty much the following:
input
when added, but this is not the way of writing in angular, this is the way of writing in jQuery$event
的对象,因为它使得我必须在 controller
to mix in code related to DOM or Event instead of business logic. Of course there are many solutions, such as: listItem.text
保存文字内容,然后在添加的时候给它生成一个递增的 listItem.id
。这样做有很多好处,比如说 ng-repeat
的时候可以 track by
,控制模版输出也会更灵活,绑定的事件处理方法可以不传 $event
而是传 item
或 item.id
you can waitphpcn_u15822017-05-15 16:55:10
For dynamically inserted HTML, which contains ng parameters, angularjs generally does not parse it twice.
You can use dependency injection to call $compile to rewrite and compile local code.