里面NG-秀前pression在AngularJS每个型号更改后解雇了吗​​? [英] Is expression inside ng-show fired after every model change in AngularJS?

查看:123
本文介绍了里面NG-秀前pression在AngularJS每个型号更改后解雇了吗​​?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的控制器标记

I have this simple controller markup

<div ng-controller="TestCtrl" ng-show="isVisible()">
    <input type="text" ng-model="smth"/><br>
    <span>{{smth}}</span>
</div> 

和控制器本身

function TestCtrl($scope, $log)
{
    $scope.smth = 'smth';

    $scope.isVisible = function(){
        $log.log('isVisible is running');

        return true;
    }
}

为什么 ISVISIBLE运行控制台模式后,每个小变化(例如改变文本框里面一个字母),我可以看到?它不是为这种情况下的问题,但我认为这将是在大型的应用程序。我能避免这种情况?

Why after every little change of model (e.g. changing one letter inside textbox) I can see isVisible is running in console? It's not problem for such case but I think it will be in large application. Can I avoid this?

推荐答案

这是正常的,因为这是AngularJS如何做它的魔力必不可少拍拍。这个答案有更多的细节: http://stackoverflow.com/a/9693933/1418796

This is normal as this is essential pat of how AngularJS does its "magic". This answer has more details: http://stackoverflow.com/a/9693933/1418796

有不同的技术来确保你不会遇到性能问题,但没有,一般你无法从被评估排除那些前pressions。

There are different techniques to make sure that you don't run into performance problems but no, in general you can't exclude those expressions from being evaluated.

这篇关于里面NG-秀前pression在AngularJS每个型号更改后解雇了吗​​?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆