Javascript 如何禁用AngularJS的闪烁ng重复?
我试图在收到AngularJS提交的查询后显示一些重复的对象。 当我只看到下一页而没有任何提交查询时,ng repeat将呈现一个ng repeat的div部分,没有结果(因此为空)。为什么会发生这种情况?如何禁用以显示空结果渲染Javascript 如何禁用AngularJS的闪烁ng重复?,javascript,angularjs,coffeescript,Javascript,Angularjs,Coffeescript,我试图在收到AngularJS提交的查询后显示一些重复的对象。 当我只看到下一页而没有任何提交查询时,ng repeat将呈现一个ng repeat的div部分,没有结果(因此为空)。为什么会发生这种情况?如何禁用以显示空结果渲染 html 代码 JavaScript(从上述咖啡脚本转换而来) 代码如下。log($scope.results);显示“未定义” 确保控制器中的结果完全为空。您可以这样初始化它:$scope.results=[]初始化$scope.results到{}并在出错
- html
- JavaScript(从上述咖啡脚本转换而来)
确保控制器中的结果完全为空。您可以这样初始化它:
$scope.results=[]
初始化$scope.results
到{}
并在出错时将其默认为{}
,而不是未定义
(function() {
var findFeeds, kindlers;
google.load("feeds", "1");
kindlers = angular.module("kindlers", ["ngSanitize"]);
findFeeds = function($scope) {
return google.feeds.findFeeds($scope.query, function(result) {
console.log($scope.query);
if ($scope.query === "undefined" || result.error) {
$scope.results = void 0;
} else {
$scope.results = result.entries;
}
return $scope.$apply();
});
};
this.mainCtrl = function($scope, $http) {
console.log($scope.results);
return $scope.doSearch = function() {
return google.setOnLoadCallback(findFeeds($scope));
};
};
}).call(this);
google.load "feeds", "1"
kindlers = angular.module("kindlers", [ "ngSanitize" ])
findFeeds = ($scope)->
google.feeds.findFeeds $scope.query, (result) ->
console.log $scope.query
if $scope.query == "undefined" || result.error
$scope.results = {}
else
$scope.results = result.entries
$scope.$apply()
@mainCtrl = ($scope, $http) ->
$scope.results = {}
console.log($scope.results)
$scope.doSearch = ->
google.setOnLoadCallback findFeeds($scope)
ng show=“result.length>0”怎么样?你能显示你的控制器代码吗?@Oledje,上面是控制器的代码。你不应该将$results对象设置为undefined。将其初始化为空数组,当没有结果时,将其设置回空数组…$scope.results=[];@gipcompany你的控制器可以继承此值来自父控制器的(
$scope.results
)。@emilioicai,$scope.results在mainCtrl显示未定义之后立即显示。@Oledje,在这种情况下我应该重命名结果吗?我不认为此控制器只存在一个,因此它不会从任何控制器继承任何值。只需尝试将此属性的值设置为空数组(“[]”)在初始化时。这不是必需的,请检查此示例,当列表为空时,不显示带有ng repeat指令的div:@Alexander,我添加了ng show=“results”,但我得到了相同的结果。谢谢philippd,很高兴知道。我在@gipcompany更改了我的答案
(function() {
var findFeeds, kindlers;
google.load("feeds", "1");
kindlers = angular.module("kindlers", ["ngSanitize"]);
findFeeds = function($scope) {
return google.feeds.findFeeds($scope.query, function(result) {
console.log($scope.query);
if ($scope.query === "undefined" || result.error) {
$scope.results = void 0;
} else {
$scope.results = result.entries;
}
return $scope.$apply();
});
};
this.mainCtrl = function($scope, $http) {
console.log($scope.results);
return $scope.doSearch = function() {
return google.setOnLoadCallback(findFeeds($scope));
};
};
}).call(this);
google.load "feeds", "1"
kindlers = angular.module("kindlers", [ "ngSanitize" ])
findFeeds = ($scope)->
google.feeds.findFeeds $scope.query, (result) ->
console.log $scope.query
if $scope.query == "undefined" || result.error
$scope.results = {}
else
$scope.results = result.entries
$scope.$apply()
@mainCtrl = ($scope, $http) ->
$scope.results = {}
console.log($scope.results)
$scope.doSearch = ->
google.setOnLoadCallback findFeeds($scope)