这篇文章主要介绍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中如何实现组件内用函数向外传值”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!