2024年最新AngularJS进阶(四)ANGULAR(1),前端面试必问

JavaScript 和 ES6

在这个过程你会发现,有很多 JS 知识点你并不能更好的理解为什么这么设计,以及这样设计的好处是什么,这就逼着让你去学习这单个知识点的来龙去脉,去哪学?第一,书籍,我知道你不喜欢看,我最近通过刷大厂面试题整理了一份前端核心知识笔记,比较书籍更精简,一句废话都没有,这份笔记也让我通过跳槽从8k涨成20k。

JavaScript部分截图

如果你觉得对你有帮助,可以戳这里获取:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

“myOptions”: [

{

“id”: 106,

“group”: “Group 1”,

“label”: “Item 1”

},

{

“id”: 107,

“group”: “Group 1”,

“label”: “Item 2”

},

}

// Get stream in the object called data

$scope.myOptions = data.myOptions;

The good thing is, you have a pretty flat data stream. When I started with this feature, I had an array of groups each containing the specific items.

It was not possible for me to fill a select box that way. Instead, I refactored some of my code to what you can see above.

Angular.js would take care of the grouping on it’s own.

Here is my select definition:

<select

ng-model=“myOption”

ng-options=“value.id as value.label group by value.group for value in myOptions”>

ng-model is the name of the property which will reference the selected option. ng-options is the directive which fills the dropdown. It deserves a bit more attention.

You will understand it more easily if you read it from right to left. First there is:

for value in myOptions

It means you’ll iterate through elements which are stored in myOptions. Every element will become available in this expression with the name “value”.

The next part is:

group by value.group

This will tell Angular.js to make up

tags and the label attribute will be filled with the content of the group field.

The last one is:

value.id as value.label

In this case, value.id will become the model (stored in ng-model), if your users have chosen an option. If you would delete “value.id as”, simply the whole value object would become the model.

value.label

does exactly what it looks like: it’s the label of the select box.

If you run your code, you’ll see something like that:

Item 1

JavaScript 和 ES6

在这个过程你会发现,有很多 JS 知识点你并不能更好的理解为什么这么设计,以及这样设计的好处是什么,这就逼着让你去学习这单个知识点的来龙去脉,去哪学?第一,书籍,我知道你不喜欢看,我最近通过刷大厂面试题整理了一份前端核心知识笔记,比较书籍更精简,一句废话都没有,这份笔记也让我通过跳槽从8k涨成20k。

JavaScript部分截图

如果你觉得对你有帮助,可以戳这里获取:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

  • 10
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值