2015-01-21 3 views

답변

4
angular.module('yourApp').controller('Contacts', ['$scope',function($scope){ 
    $scope.contacts = [ 
    {name:'Hazem', number:'01091703638'}, 
    {name:'Taha', number:'01095036355'}, 
    {name:'Adora', number:'01009852281'}, 
    {name:'Esmail', number:'0109846328'} 
    ]; 
}]) 

위 코드에서 "연락처"가보기로 전달됩니다. 그것은 다음과 같이 제어 요소 내에서 사용할 수 있습니다 :

<div ng-controller="Contacts">{{contacts[0].name}}</div> 

그래서 우리는 우리가보기에 전달 된 $ 범위 개체에 액세스 할 수 있습니다, 우리가 사용하고자하는 컨트롤러를 정의했다. 아래 예제처럼 $ scope에 원하는만큼 항목을 추가 할 수 있습니다 :

angular.module('yourApp').controller('Contacts', ['$scope',function($scope){ 
    $scope.contacts = [ 
    {name:'Hazem', number:'01091703638'}, 
    {name:'Taha', number:'01095036355'}, 
    {name:'Adora', number:'01009852281'}, 
    {name:'Esmail', number:'0109846328'} 
    ]; 
    $scope.rabbit = "Rabbit"; 
}]) 
+0

고마워, 내가 너에게 알려 줄게. –

+0

전혀 작동하지 않는다. –

관련 문제