小编Oma*_*eky的帖子

为什么AngularJS过滤器只运行一次?

请考虑以下示例:

    angular.module('app', []).controller('TestController', function($scope) {
      $scope.getText = function() {
          console.log('getting text');
          return 'text';
      };
  }).filter('text', function() {
      return function() {
          console.log('text filter');
          return 'text';
      };
  });
Run Code Online (Sandbox Code Playgroud)
 

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<div ng-app="app" ng-controller="TestController">
    <p>{{getText()}}</p>
    <p>{{'' | text}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)

请注意,该getText()函数运行两次,而过滤器只运行一次.我假设该getText()函数运行两次以确保模型现在稳定.为什么过滤器的行为不一样?

html javascript angularjs

4
推荐指数
1
解决办法
710
查看次数

LINQ查询中的NullReferenceException

我在这个LINQ查询中得到一个不寻常的"NullReferenceException未被用户代码处理"错误:

List<UDIDInfo> d2Android = d2.Where(x.DeviceOS == (byte)DeviceOS.Android).ToList();
Run Code Online (Sandbox Code Playgroud)

我继续并添加了一个空检查,但仍然收到错误

List<UDIDInfo> d2Android = d2.Where(x => x.DeviceOS != null && x.DeviceOS == (byte)DeviceOS.Android).ToList();
Run Code Online (Sandbox Code Playgroud)

请注意,(byte)DeviceOS.Android并且d2都不为空

编辑(解决方案):

List<UDIDInfo> d2Android = d2.Where(x => x != null && x.DeviceOS != null && x.DeviceOS == (byte)DeviceOS.Android).ToList();
Run Code Online (Sandbox Code Playgroud)

c# linq nullreferenceexception

2
推荐指数
1
解决办法
9455
查看次数

标签 统计

angularjs ×1

c# ×1

html ×1

javascript ×1

linq ×1

nullreferenceexception ×1