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
The typical way to declare the model in the controller... something like:
var mainApp=angular.module('mainApp',[])
.controller('myControl',['$scope','$http',function($scope,$http){
$scope.inputvar = "Hello World";
$http.get('./myjson.json').success(function(fdatas){
$scope.datas=fdatas;
});
}])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With