각도를 찾기 시작했는데 왜 내 데이터가 내 지시문에 전달되지 않는지 알 수 없습니다. https://plnkr.co/edit/ONwYevQ4NbvBVjTwARHl?p=preview이컨트롤러 데이터가 지시문에 전달되지 않았습니다.
내 코드 : app.js는 :
이var app = angular.module('mjApp', []);
app.controller('MainController', ['$scope', '$http', function ($scope, $http) {
$scope.name = "m.jacionis";
$scope.avatar = null;
$scope.fetchData = function(){
var callUrl = 'https://api.github.com/search/users?q=' + $scope.name;
$scope.avatar = "http://images.clipartpanda.com/sad-face-clipart-black-and-white-9c4eqRyyi.png";
$http({
method: 'GET',
url: callUrl
}).then(function successCallback(response) {
$scope.avatar = response.data.items.length > 0 ?
response.data.items[0].avatar_url : $scope.avatar;
console.log($scope.avatar);
}, function errorCallback(response) {
console.log('avatar stays the same');
});
};
}]);
app.directive("mjDirective", function(){
return {
restrict: "EA",
templateUrl: 'template.html',
scope: {
name: "=name",
avatar: "=avatar"
}
};
});
index.html을 :
이<!DOCTYPE html>
<html ng-app="mjApp">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div class="parent" ng-controller="MainController">
<div class="line">
<input type='text' ng-model='name' />
<input type="button" ng-click="fetchData()" value="Submit User Name" />
</div>
<mj-directive name=name userAvatar=userAvatar></mj-directive>
</div>
</body>
</html>
template.html :
<div class='line'>
<p>Name : <strong>{{name}}</strong></p>
<img class="avatar" src={{avatar}}/>
</div>
name
값이 여기 코드가 통과했지만, 내가 가져올 때 얻을 수있는 값 avatar
데이터가 아닙니다. 알아낼 수없는 것, 왜 그렇게 느껴지나요? 어떤 아이디어 나 제안이 많은 도움이 될 것입니다.
'아바타 :
<mj-directive name="name" userAvatar="userAvatar"></mj-directive>
또한 지시자 안에 당신이해야 "= 아바타"'그러나 당신이 전달하는'userAvatar' – taguenizy