for my angular i have the following:
this is the html
<div ng-app='mainApp' ng-controller='myControl'>
<mydirective datas="datas"></mydirective>
</div>
js file
var mainApp=angular.module('mainApp',[])
.controller('myControl',['$scope','$http',function($scope,$http){
$http.get('./myjson.json').success(function(fdatas){
$scope.datas=fdatas;
});
}])
.directive('mydirective',function(){
return{
restrict:'E',
scope:{
datas:'='
},
template:"<input type='text' ng-model='inputvar'/>",
controller:function($scope,window){
$scope.inputvar=$scope.datas[0].name;
}
}
});
json file
[{ name:'test'},{name:'test2'}]
for some reason when i checked the debug console, it comes undefined and initial value can't be set. any idea?
thank you
$scope.inputvar = "Hello World";in your controller.$scope.datasbefore$httplike this$scope.datas=[]