Angularjs $scope variables not updating in view

Mr.Haze

I'm new to Angularjs and im trying to update two $scope variables in two seperate functions which are called on ng-click.

Even though the variables update, they wont rebind in the view.

HTML

<div ng-app="">
<div ng-controller="MainCtrl">
     <p> <a href="#" ng-click="getDetails();getElse()">Refresh</a> </p>
    <p ng-controller="MainCtrl"><span ng-bind="something"></span></p>
       <p ng-controller="MainCtrl"><span ng-bind="somethingelse"></span></p>
</div>
</div>

JS function MainCtrl($scope) {

$scope.something = "something";
$scope.somethingelse = "else";

$scope.getDetails = function () {
     alert("getdetails before change: "+$scope.something);
    $scope.something = 'changed';
    alert("getdetails: "+$scope.something);
};

$scope.getElse = function () {
    alert("getElse before change: "+$scope.somethingelse);
    $scope.somethingelse = 'changed';
    alert("getElse: "+$scope.somethingelse);
    };

}

I've created a fiddle to show you what i mean: http://jsfiddle.net/M3pZ8/

can anyone tell me what is the correct way to do this?

Thanks in advance.

tymeJV

It's because you have MainCtrl declared 3 times, effectively creating 3 separate scopes. You only need it once, at the top.

<div ng-controller="MainCtrl">
    <p> <a href="#" ng-click="getDetails();getElse()">Refresh</a> </p>
    <p><span ng-bind="something"></span></p>
    <p><span ng-bind="somethingelse"></span></p>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Angularjs $scope variables not updating in view

From Dev

AngularJS - variables not updating in view (not using scope)

From Dev

angularJS $scope change not updating view

From Dev

Auto-updating scope variables in angularjs

From Dev

Ionic: AngularJS Variables not Updating DOM with $scope

From Dev

AngularJS $scope.push not updating the view from a $http data response

From Dev

AngularJS $Broadcast and $on not updating $scope

From Dev

AngularJS directive scope not updating

From Dev

Angularjs not updating variables

From Dev

Angular $scope variables not updating in controller

From Dev

AngularJs scope variables in console

From Dev

Testing AngularJS scope variables

From Dev

AngularJS service is not updating the view

From Dev

AngularJS : view not updating

From Dev

AngularJS view not updating

From Dev

AngularJS loops not updating the view

From Dev

updating a date on AngularJS view

From Dev

AngularJS scope integer not updating on template

From Dev

AngularJS directive: Updating the isolated scope

From Dev

Angularjs xeditable typehead not updating the scope

From Dev

Angularjs scope variable not updating as expected

From Dev

Updating model without scope in AngularJS

From Dev

scope passed to service is not updating the view

From Dev

AngularJS - My error messages aren't updating when their trigger variables are changed in the scope?

From Dev

AngularJS: accessing scope variables in $routeProvider

From Dev

AngularJS: accessing scope variables in $routeProvider

From Java

AngularJS view not updating on model change

From Dev

AngularJS - model changes not updating the view

From Dev

AngularJS View not updating ourside src

Related Related

HotTag

Archive