AngularJS學習筆記一

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   使用   for   sp   div   

1、 Select下拉式清單方塊的使用:

<select ng-model="selected" ng-options="user.id as user.name for user in users | orderBy:‘age‘ "></select>

①添加“ng-model”指令,代表下拉框綁定的實體物件

②添加“ng-options”指令,指令的形式四種:

1) model.text for model in array;

2) mode.value as model.text for model in array;

3) model.text grou by group for model in array;

4) model.value as model.text group by group for model in array;

以上②和④中的model.value是下拉式清單各個項的value值,可以將其綁定為array數組中一個元素的的某個屬性,也可直接綁定為array數組中單個元素對象,

即 mode as model.text for model in array;

③為下拉框設定預設選中項,selected=users[0].id

2、服務(Service)

建立服務有多種種方式:Factory、Service、Provider、Decorator、Constant、Value

介紹幾種常用建立服務方法:①Factory ②Service ③Provider

1、Factory可建立多個服務,然後將Factory名稱注入到Controller中去,使用Factory對象來擷取具體的服務物件。

2、Service只建立一個特定的具體服務,再注入到Controller中去使用。

3、Provider提供一個具體的服務+服務的配置資訊。通過指定服務的配置資訊,來實現一個服務的多種表現形式,以適配各種需求。

各建立服務的方式代碼如下:

① Factory

app.factory(“myFactory”,function(){  var services={    “serviceName1”:function() { ... }, //服務1     “serviceName2”:function() { ... }, //服務2     “serviceName3”:function() { ... }, //服務3     ……  };  return  services; //將所有服務返回(原廠模式)})

 

② Service

app.service(“myService”,function(){  var service = function() { ... } //具體服務  return  service; //返回具體服務})

 

③ Provider

app.factory(“myProvider”,function(){  var provider={    “serviceName”:function() { ... }, //服務    “config”: { ... }, //配置資訊  };  return  provider; //將所有服務和配置資訊返回(通過配置讓服務表現不同結果)})

 

調用時,修改配置: 

app.config(function(myProviderProvider){    myProviderProvider.config = {.....} //修改配置});

 

 

AngularJS學習筆記一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.