V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
IceHazymoon
V2EX  ›  问与答

AngularJS ng-if 判断 执行方法会执行两次?

  •  
  •   IceHazymoon · Nov 20, 2017 · 2347 views
    This topic created in 3083 days ago, the information mentioned may be changed or developed.

    正在学习 AngularJS 的萌新,今天在用 ng-if 做判断的时候执行的方法会执行两次,貌似和数据双向绑定的过程有关,请问该如何解决

    HTML

    <div ng-if="data()"></div>
    

    JS

    $scope.data = function () {
    	alert()
    }
    
    1 replies    2017-11-20 22:16:34 +08:00
    billlee
        1
    billlee  
       Nov 20, 2017
    别在里面写有副作用的代码就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2486 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:14 · PVG 15:14 · LAX 00:14 · JFK 03:14
    ♥ Do have faith in what you're doing.