我正在测试ng-show
和AngularJS表达式,但我找到了一些我无法理解的东西.我创建了一个变量displayed
并'false'
为其分配了一个字符串(不是布尔值).表达式displayed && true
被计算为true,第二个div显示没有问题(因为字符串和true应该为true).我知道Angular表达式和JavaScript表达式之间存在一些差异,但是我不知道为什么没有显示第一个div; 似乎displayed
是由Angular编译为布尔值.
这是jsfiddle:http://jsfiddle.net/micmia/1psf70tv/3/
模板:
<div ng-controller="MyCtrl">
<div ng-show="displayed">test1</div>
<div ng-show="displayed && true">test2</div>
</div>
Run Code Online (Sandbox Code Playgroud)
控制器:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope, $parse) {
$scope.displayed = 'false';
});
Run Code Online (Sandbox Code Playgroud) 我一直试图通过使用将一些项目添加到可滚动容器中的列表中ng-repeat
,并且最近的项目应位于列表的顶部.如果在添加内容时容器的滚动条不在顶部,我还需要保持滚动位置.
这是我的解决方案,但我仍有问题.在角度为dom渲染前置项目后,总是会出现闪烁.
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl', function($scope, $interval, $timeout) {
$scope.items = [];
$interval(function() {
var item = {
id: Math.random(),
text: (new Date()).toString()
};
$scope.items.unshift.apply($scope.items, [item]);
var $container = $('.stream-container');
var $topItem = $('.item:first');
var oScrollTop = $container.scrollTop();
var oOffset = $topItem.length ? $topItem.position().top : 0;
$timeout(function() {
// Executed after the dom has finished rendering
if ($container.scrollTop() !== 0) {
$container.scrollTop(oScrollTop + ($topItem.length ? $topItem.position().top : 0) - oOffset);
}
});
}, 1000);
}); …
Run Code Online (Sandbox Code Playgroud)我在新的云服务器 (Ubuntu 16.04) 上安装了 Python 3.6 而不是默认的 3.5 版本。重启服务器后,发现cloud-init
启动时执行失败,syslog
.
Sep 20 16:16:14 cloud-init[1310]: Traceback (most recent call last):
Sep 20 16:16:14 cloud-init[1310]: File "/usr/bin/cloud-init", line 9, in <module>
Sep 20 16:16:14 cloud-init[1310]: load_entry_point('cloud-init==0.7.9', 'console_scripts', 'cloud-init')()
Sep 20 16:16:14 cloud-init[1310]: File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 570, in load_entry_point
Sep 20 16:16:14 cloud-init[1310]: return get_distribution(dist).load_entry_point(group, name)
Sep 20 16:16:14 cloud-init[1310]: File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 2751, in load_entry_point
Sep 20 16:16:14 cloud-init[1310]: return ep.load()
Sep 20 16:16:14 cloud-init[1310]: File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 2405, …
Run Code Online (Sandbox Code Playgroud) angularjs ×2
javascript ×2
cloud-init ×1
dom ×1
jquery ×1
python ×1
python-3.x ×1
scroll ×1
ubuntu ×1