zoukankan      html  css  js  c++  java
  • 全栈老司机roadmap笔记--------angular js(3)

    level4

    当我们需要打印多次product name 和product price的时候,我们要重复利用这2行代码

    如果要传入string,那么用“” 里面包含‘’。利用ng-include

    加载页面以后,用ajax call来拿到需要include的page

    ---------------------------分割线-----------------------------

    a better way to include html template is to create custom directive

    use directive to replace ng-include!

    derective allows you to express behavior of your application!

    use custom directive to express behavior example:

    expressivness is the real power of using custom directive 

    several kinds of custom directives:

     How can we define custom directive?

    the second part is an anonymous function which return a directive defination object

    note that the dash in html translates to CamelCase in javaScript! 

    Element directive

    attribute directive

    Attribute Directive vs Element Directive

    Angular make people easier to understand the behavior in html pages

    ---------------------------------i'am a line----------------------------------------------------

    what if we want to add an directive which contains an controller?

    First, we need to extract the template in to a seprate html file

    now we create the new directive in app.js, but how can we add the controller into the directive?

    move the function inside and the ailes

    ---------------------------------i'am a line----------------------------------------------------

     level 5

    dependencies

    how can we isolated some of the code in their own modules

    pull out all the product related directive to product.js file

    make it to become a new module

    now we need to add dependency

    we also need to include the file

    how to organize the modules? 

    ----------------------------------华丽丽的分割线-----------------------------------

    Current we use the data store locally in our controlloer, how can we get data from database?

    we should call an api and get json file as out data

    we need services!

    angular $http service 

    how does a controller use a service like $http or more services?

     the steps for dependency injection steps

      1. when angular load, it create an injector

      2. when angular buildin service is load, they register injector as available libraries.

      3. when application loads, they register our controller with injector.

      4. when the controller runs, it tells injector, it needs $http and $log.

       the injector pass the services in as arguments.

      ------that's called dependency injection: inject service into controller as arguments

    .success denotes when we get the data, we do something 

    can we write this.product = data? No! because this inside the callback is an service http.

    we need to initialize store.products to an empty array. Since the page renders before we get the data.

    Once we get the data, the page will automatiallty undate.

    more http services

     //to do

  • 相关阅读:
    c#类的小小理解
    sql语句:保留要害字的问题.例如 size,text,user等
    c#2005做新闻发布系统心得
    asp 遇到过的问题集锦,附加asp语句添加数据库和生成表,asp命令更改指定文件的文件名,asp值传递的应用091116小结
    dropdownlist控件失去焦点的小应用和函数substr
    获得当前应用程序路径C#03
    模糊查询简单分析,得出sql语句
    20080905经典的DataReader对象解读+几种对数据库的操作的命令,20100111update read db example
    Servlet 容器的工作原理 ( 二 )
    手低眼高 初学者学习Hibernate的方法
  • 原文地址:https://www.cnblogs.com/jiangchen/p/5930521.html
Copyright © 2011-2022 走看看