[Angular] Controller
< !DOCTYPE html >
< html ng-app = "myApp" >
< head >
< meta charset = "UTF-8" >
< title >Step02_controller.html
< script src = "js/angular.min.js" >
< script >
// angular 모듈 만들기
var myApp = angular.module( "myApp" ,[]);
// Ctrl1 이라는 이름의 컨트롤러 만들기
myApp.controller( "Ctrl1" ,[ "$scope" , function ($scope){
$scope. name = "김구라" ;
$scope.clicked = function (){
alert ( "버튼을 눌렀네?" );
};
$scope.nums = [ 10 , 20 , 30 , 40 , 50 ];
}]);
// Ctrl2 이라는 이름의 컨트롤러 만들기
myApp.controller( "Ctrl2" ,[ "$scope" , function ($scope){
$scope. name = "원숭이" ;
$scope.friends = [
{num: 1 , name : "김구라" ,addr: "노량진" },
{num: 2 , name : "해골" ,addr: "행신동" },
{num: 3 , name : "원숭이" ,addr: "동물원" }
];
}]);
< body >
< div ng-controller = "Ctrl1" >
< p >내이름은 : < strong >{{name}}
< button ng-click = "clicked()" >눌러보셈
< ul >
< li ng-repeat = "tmp in nums" >{{tmp}}
< div ng-controller = "Ctrl2" >
< p >너의 이름은 : < strong >{{name}}
< table >
< thead >
< tr >
< th >번호
< th >이름
< th >주소
< tbody >
< tr ng-repeat = "tmp in friends" >
< td >{{tmp.num}}
< td ng-bind = "tmp.name" >
< td ng-bind = "tmp.addr" >
from http://heekim0719.tistory.com/164 by ccl(A) rewrite - 2020-03-07 09:21:16
댓글
댓글 쓰기