Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AngularJS 1.x 入门实践 #60

Open
ufologist opened this issue Mar 7, 2017 · 0 comments
Open

AngularJS 1.x 入门实践 #60

ufologist opened this issue Mar 7, 2017 · 0 comments

Comments

@ufologist
Copy link
Member

入门资源

使用感受

2015/9/23 @ufologist

  • 最痛苦的莫过于作用域(scope)了, 有时候真不知道这个数据是从哪个作用域(子作用域基于原型链继承父作用域)上下来的

  • 双向数据绑定是把双刃剑, 带来了方便也带来了混乱, 就怕子作用域不小心修改到了父作用域的东西

  • scope 中放两种数据共同组成一个界面

    • vm: 界面中的基础数据, 可能是前端写死的数据, 也可能是后端返回的基础数据
    • model: 直接映射界面的数据模型, 一般对应后端返回的数据

    例如: 一个界面中表单的 select 控件, 它需要基础数据来填充选项, 因此会用 vm.keywords 来做初始化数据的绑定. 对于选中的值(需要从 keywords 中选), 就是直接映射到界面的数据模型, 因此会用 model.keyword 绑定用于的选择项, 继而提交给后端.

    $scope.vm = {
        keywords: ['a', 'b', 'c']
    };
    $scope.model = {
        keyword: 'a'
    };

常见问题

  • AngularJS: $digest vs $apply

    $apply: all watchers are checked, the entire application starts the $digest loop.
    $digest: starts the $digest cycle for the current scope and its children. You should notice that the parents scopes will not be checked and not be affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant