私は角度を探し始めましたが、私のデータが私のディレクティブに渡されない理由を理解できないようです。 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