javascript - angular, pass a scope into a function (passing scope as variable?) -
javascript - angular, pass a scope into a function (passing scope as variable?) -
i'm trying pass scope function , can't seem work correctly. here's have -
ng-click="clickfunction(scope1)" //the function $scope.clickfunction = function(passedscope){ passedscope = false; console.log($scope.scope1);
so - it's prett straight forwards want pass in scope , set false in click. when log scope after changing hwever still says it's true. tried -
$scope.passedscope
what trying set $scope.scope1 = false. set in top of controller true , controls button nearby button having ng-disabled="!scope1", cant scope1 =!scope! on click because goes through modal confirm user wants finish runs modalinstance.result.then(function () { there need set passed scope false. phone call scope directly, i'm trying create function can utilize across multiple delete functions, trying pass scope needs changing false.
i thinking pass scope through function.
thanks!
update according @josep showed me today able create work around passing scope string so
ng-click="clickfunction('scope1')"
and doing
$scope[passedscope] = false;
if want pass current scope of part of view function, way be:
ng-click="clickfunction(this)"
but in function should treating scope this:
$scope.clickfunction = function(passedscope){ passedscope.somepropertyofthescope = false;//<---notice difference code suggesting.
you can't set scope
false
, can set 1 of properties false
, not scope itself. wouldn't create sense because scope
object holds set of properties, events , functions. of them inherited scope ancestors $rootscope
, , of them custom.
maybe trying pass 1 of properties of scope
parameter of function, can alter in function. however, in javascript way pass parameter reference pass object , update 1 of properties, if pass boolean property function, passing value of boolean property, not reference. please have @ this: pass variables reference in javascript.
javascript angularjs
Comments
Post a Comment