2024年前端最新AngularJS进阶(四)ANGULAR,10大前端常用算法

专业技能

一般来说,面试官会根据你的简历内容去提问,但是技术基础还有需要自己去准备分类,形成自己的知识体系的。简单列一下我自己遇到的一些题

最近得空把之前遇到的面试题做了一个整理,包括我本人自己去面试遇到的,还有其他人员去面试遇到的,还有网上刷到的,我都统一的整理了一下,希望对大家有用。

其中包含HTML、CSS、JavaScript、服务端与网络、Vue、浏览器等等

由于文章篇幅有限,仅展示部分内容

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

Item 2

Please look again and check the value attribute of the options. You might have expected it’s matching the IDs from your JSON,

but that is not the case (and yes, I thought like this initially). Actually this is an increasing number and references the position of the model

(which is an array in my case). Don’t worry about that - if you select your option the correct ID will be selected and put into your model.

Or, if you leave out the value.id part of the expression, the whole selected object will become your model.You can easily test it.

<select

ng-change=“selectAction()”

ng-model=“myOption”

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

ng-change will fire if the user has chosen something. You can output it by typing:

$scope.selectAction = function() {

console.log($scope.myOption);

};

I find the syntax of ng-options pretty much counter intuitive. It took me a good while to understand it and I was glad about the nice help on the AngularJS mailinglist. 
总结:

  • 函数式编程其实是一种编程思想,它追求更细的粒度,将应用拆分成一组组极小的单元函数,组合调用操作数据流;

  • 它提倡着 纯函数 / 函数复合 / 数据不可变, 谨慎对待函数内的 状态共享 / 依赖外部 / 副作用;

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

Tips:

其实我们很难也不需要在面试过程中去完美地阐述出整套思想,这里也只是浅尝辄止,一些个人理解而已。博主也是初级小菜鸟,停留在表面而已,只求对大家能有所帮助,轻喷🤣;

我个人觉得: 这些编程范式之间,其实并不矛盾,各有各的 优劣势

理解和学习它们的理念与优势,合理地 设计融合,将优秀的软件编程思想用于提升我们应用;

所有设计思想,最终的目标一定是使我们的应用更加 解耦颗粒化、易拓展、易测试、高复用,开发更为高效和安全

  • 13
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值