angularjs1.5 组件内用函数向外传值的实例
程序员文章站
2022-07-04 17:42:39
组件:
.component('homecitylistcom',{
bindings: {
list: '<',
cityname:'&...
组件:
.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 组件内用函数向外传值的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。