angularjs1.5 组件内用函数向外传值的实例
更新时间:2018年09月30日 09:31:18 作者:yzbben
今天小编就为大家分享一篇angularjs1.5 组件内用函数向外传值的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
组件:
.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>
路由设置:
.state('city_list',{
url:"/city_list",
templateUrl:'templates/indexTpl/city_list.html',
controllerAs:'cl',
controller:'cityListCtrl'
})
以上这篇angularjs1.5 组件内用函数向外传值的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
AngularJS通过ng-Img-Crop实现头像截取的示例
本篇文章主要介绍了AngularJS通过ng-Img-Crop实现头像截取的示例,具有一定的参考价值,有兴趣的可以了解一下2017-08-08
Angular 的 Change Detection机制实现详解
这篇文章主要为大家介绍了Angular 的 Change Detection机制实现详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-10-10
如何处理Angular 错误消息ERROR Error NullInjectorError No provid
这篇文章主要介绍了如何处理Angular 错误消息ERROR Error NullInjectorError No provider for XX2023-07-07


最新评论