I have seen some questions similar to this one, but I cannot resolve my issue. I have angular controller:
app.controller('MyFormCtrl', function($scope, Item) {
$scope.searchResult = {value: 'Test'};
$scope.search = function() {
console.log($scope.searchResult);
$scope.searchResult.value = "Clicked";
}
}
And html template:
<div ng-controller="MyFormCtrl">
<p>{{searchResult.value}}</p>
<p align="center"><a href="#" ng-click="search()">Search</a></p>
</div>
And I cannot force it to reflect changes that are made in controller. At load I see default values of variables: 'Test' and 'Test name'. But when I click register button new values are assinged to variables in controller, but no changes at html page. I suppose there is some problem with scopes. I'm new at angularjs and SO cannot help me, so I suppose it is time for some special help on my particular case.
Update 1. Item - is a resource to rest api, it works and I see result in firebug during debugging, but it does not matter. Even if I delete this line, nevertheless searchResult does not update. But in JS console after 1st click I see value 'Test' (it is correct), on second click I see in cosole value 'Clicked', which means that new value were assinged, I see the same during debug in firebug, but on html page I still see value 'Test'. I have tried to do $scope.$apply() - it does not help. The most closest case that I managed to find are this question: changing a controller scope variable in a directive is not reflected in controller function, but here I see more complex logic.
Update 2. There are a lot of answers, which were confused with Item call. I have deleted Items call, and make code as simple as it possible. It still does not reflect changes of variable searchResult.
Update 3. There is no issue, I have started from simple example and get working result, seems like and introduced some error in initial project during.
Item.search()errors out,$scope.searchResult.value = "Clicked";is never reached. Have you tried removing that line?Item.search()function does. There isn't anything obvious about the code that you have posted here that would explain why it's not functioning.Item.search()return a different array of objects? Because if it is not returning anything then$scope.searchItemswon't update from the click event.