angularjs1.5 組件內(nèi)用函數(shù)向外傳值的實(shí)例
組件:
.component('homeCityListCom',{
bindings: {
list: '<',
cityname:'&'
},
controllerAs: 'vm',
template:
`
<div class="cityListBox">
<span class="title">按拼音首字母選擇</span>
<div class="cityItem flexRowStart" ng-repeat="x in vm.list track by $index">
<p class="zimu flexColumnCenter">{{x.sortName}}</p>
<ul class="flexRowStart city">
<li ng-repeat="c in x.cities"><a href="/#!/home?city_id={{c.cityId}}" rel="external nofollow" ng-click="vm.cityname({name: c.cityName})">{{c.cityName}}</a></li>
</ul>
</div>
</div>`
})
控制器:
.controller('cityListCtrl', ['$scope','$http', function ($scope,$http) {
let that = this;
// 將城市名字存在本地
that.cityName = function(name){
console.log(123);
localStorage.setItem('cityName', name);
}
}])
使用組件:
<home-city-list-com list="cl.cityList" cityname="cl.cityName(name)"></home-city-list-com>
路由設(shè)置:
.state('city_list',{
url:"/city_list",
templateUrl:'templates/indexTpl/city_list.html',
controllerAs:'cl',
controller:'cityListCtrl'
})
以上這篇angularjs1.5 組件內(nèi)用函數(shù)向外傳值的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解angular2.x創(chuàng)建項(xiàng)目入門指令
這篇文章主要介紹了詳解angular2.x創(chuàng)建項(xiàng)目入門指令,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10
AngularJS constant和value區(qū)別詳解
angularJS可以通過constant(name,value)和value(name,value)對于創(chuàng)建服務(wù)也是很重要的。他們之間有什么不同呢?今天小編給大家分享AngularJS constant和value區(qū)別詳解,需要的朋友參考下2017-02-02
在AngularJS中如何使用谷歌地圖把當(dāng)前位置顯示出來
這篇文章給的大家介紹在AngularJS中如何使用谷歌地圖把當(dāng)前位置顯示出來,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,對angularjs 谷歌地圖相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2016-01-01
AngularJS通過ng-Img-Crop實(shí)現(xiàn)頭像截取的示例
本篇文章主要介紹了AngularJS通過ng-Img-Crop實(shí)現(xiàn)頭像截取的示例,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08
Angular 的 Change Detection機(jī)制實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Angular 的 Change Detection機(jī)制實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Agularjs妙用雙向數(shù)據(jù)綁定實(shí)現(xiàn)手風(fēng)琴效果
最近在工作總遇到需要實(shí)現(xiàn)類似手風(fēng)琴效果的需求,下面小編通過本文給大家分享angularjs巧用雙向數(shù)據(jù)綁定實(shí)現(xiàn)手風(fēng)琴效果,需要的朋友可以參考下2017-05-05
如何處理Angular?錯(cuò)誤消息ERROR?Error?NullInjectorError?No?provid
這篇文章主要介紹了如何處理Angular?錯(cuò)誤消息ERROR?Error?NullInjectorError?No?provider?for?XX2023-07-07

