I don't think your code is correct. You've created func1 and func2 outside 
the controller and you're trying to get the scope by reference in the 
jqLite instance(?). It looks really confusing.

I suggest you to follow the tutorial in the docs 
<https://docs.angularjs.org/tutorial> to understand Controllers, $scope and 
two-way 
data binding <https://docs.angularjs.org/tutorial/step_04>.

On Wednesday, June 11, 2014 6:15:54 PM UTC-3, Ning Jiang wrote:
>
> Hi,
>
> I have an AngularJS application as follows. func1 and func2 are triggered 
> seperately to update the UI. However, the UI updates when I call func1, but 
> not func2. If I remove the div corresponding to list1 then func2 does 
> update the UI.  Since I'm pretty new to AngularJS, I'm assuming I missed 
> something pretty obvious.  Can anyone help? Thanks! 
>
> <html>
> ....
>
> <body>
>
> <div ng-app>
>     <div id="divOutput" ng-controller="OutputCtrl">
>            <div ng-repeat="info in list1">
>                 ....
>            </div>
>            <div ng-repeat="info in list2">
>                 ... 
>            </div>
>     </div>
> </body>
> </html>
>
> In the javascript, I have two functions that update the two divs 
> seperately:
>
> function OutputCtrl($scope, $sce) {
>   $scope.list1 = new Array();
>   $scope.list2 = new Array();
>
>   $(scope).addToList1 = function(item) { $scope.list1.push(item1); }
>   $(scope).addToList2 = function(item) { $scope.list2.push(item1); }
>
> }
>
> func1()
> {
>     var scope = angular.element($("#divOutput")).scope();
>     scope.$apply(function(){
>         scope.addToList1(item);
>     }); 
> }
>
> func2()
> {
>     var scope = angular.element($("#divOutput")).scope();
>     scope.$apply(function(){
>         scope.addToList2(item);
>     }); 
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to