I have a Go struct:
type Foo struct {
Name string `json:"fooName"`
Things []string `json:"things"`
}
I have an Angular html page:
<input type="text" name="fooName" ng-model="foo.fooName"/>
<div ng-repeat="thing in things">
<input ng-model="foo.things" type="text" name="thing-{{$index}}"/>
</div>
In the Angular controller I have:
$scope.save= function(){
Restangular
.all('foos/new')
.post($scope.foo).then(function(foo) {
$location.path('/admin/fooManagement');
});
};
The rest service call calls:
func CreateFoo(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
var f Foo
dec := json.NewDecoder(r.Body)
dec.Decode(&f)
log.Println("**** CreateFoo.... ")
log.Println(&d)
}
Foo's name comes through, but I cannot get the "Things" array populated with the input values. I'm trying to figure out how to get the post service call to populate the array.
I am not experienced in AngularJS, but I do know Javascript and Go pretty well:
<div ng-repeat="thing in things">
<input type="text" ng-value="foo.things[$index]" name="thing[{{$index}}]"/>
</div>
Assuming that foo.things
and things
are not the same array and that both are in scope.
With the ng-value
directive, we're binding this input's value to foo.things
' element at index $index
.
And the name
attribute follows Restangular's (undocumented) array-notation.