AngularJS开发WebAppAngular.js专场

ng-repeat与ng-model的简单搭配使用

2016-11-03  本文已影响67人  灬弑念

目标实现:通过点击<li>标签的点击事件改变<p>标签的内容

<div ng-app="MyApp" ng-controller="MyCtrl">

<p ng-model ="myText" ng-init = "myText = '大连'">{{myText}}</p>

<ul>

<li ng-repeat = "x in citys">

<a href="#" ng-click="myClick(x)">{{x}}</a>

</li>

</ul>

</div>

<script>

var myApp = angular.module("MyApp", []);

myApp.controller("MyCtrl", function ($scope){

$scope.citys = ["大连", "北京", "上海"];

$scope.myClick = function (x){

$scope.myText = x;

};

});

</script>

上一篇下一篇

猜你喜欢

热点阅读