I have the following in my HTML:
<body ng-controller = "Control as control">
<button ng-click = "control.prepareAction()">Do Action </button>
<div id="one" ng-hide = "!control.showOne" >
<div>
<h6> {{control.name}}</h6>
<p> Bills Sponsored: {{control.count}} <p>
</div>
</body>
And in my Javascript:
var vm = this;
vm.name = "My Name"
vm.prepareAction = function(){
action(parseFirst(), parseLast()); //The two parse functions simply get values from an HTML form. This works correctly.
}
function action(first, last) {
$.post('php/one.php', {
first: first,
last: last
},
function(data) {
create(JSON.parse(data));
});
return values;
}
function create(data) {
var countArray = data[0];
vm.count = countArray[0];
vm.showOne = true;
}
This function does not update the values of showOne (the div is always hidden) or count (it is blank when I set ng-hide to false) in the HTML. However, when I set ng-hide to false, it shows the name correctly. This makes me think it is a scope issue, however, when I print the value of vm to the console, the values for showOne and count are correct. This is confirmed by the Chrome ng-inspector Extension.