javascript – 防止初始显示角度模板
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 防止初始显示角度模板,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2008字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 防止初始显示角度模板](/upload/InfoBanner/zyjiaocheng/788/e78b24894e054445880c29e20a176b53.jpg)
我正在关注一个在线示例.但是,它并没有像我希望的那样工作.现在,我可以轻松地使用jQuery和一个类,但我试图用“Angular Way”来做.
我的标签的角度模板最初显示.一旦范围开始处理,它就会隐藏&标签在绑定时按预期进入.
问:如何防止角度模板表单最初显示?
更新:
应用“ng-bind”只会改变问题的性质.它没有解决问题.
我的MARKUP看起来像:
<div ng-controller="BlogsIndexController">
<div class="tags-cloud tags-cloud-category" ng-show="isShown">
<div class="tag" ng-repeat="category in categories">
<a href="#" data-iso-sort="iso-sort-category-{{category.SortKey}}">{{category.Name}}</a>
</div>
</div>
</div>
我的控制器看起来像:
// CONTROLLER
application.controller('BlogsIndexController', function ($scope, $http, categoryTagsDataService) {
var vm = this;
// Internal
vm.on = {
databind: {
categories: function () {
var categories = categoryTagsDataService.list()
categories.success(function (data) {
$scope.categories = data;
$scope.isShown = true;
});
}
}
};
vm.databind = function () {
vm.on.databind.categories();
};
// Scope
$scope.isShown = false;
$scope.categories = [];
// Initialize
vm.databind();
});
解决方法:
您应该使用ngBind =“category.Name”而不是{{category.Name}}:
<a href="#" data-iso-sort="iso-sort-category-{{category.SortKey}}"
ng-bind="category.Name"></a>
It is preferable to use ngBind instead of {{ expression }} if a template is momentarily displayed by the browser in its raw state before Angular compiles it. Since ngBind is an element attribute, it makes the bindings invisible to the user while the page is loading.
更多信息here.
更新1:
我从未使用过ngCloak,但是docs说它可以帮到你:
<a href="#" data-iso-sort="iso-sort-category-{{category.SortKey}}"
ng-bind="category.Name" ng-cloak></a>
更新2:
我已经检查了this答案,似乎你还需要添加下一个CSS规则:
/*
Allow angular.js to be loaded in body, hiding cloaked elements until
templates compile. The !important is important given that there may be
other selectors that are more specific or come later and might alter display.
*/
[ng\:cloak], [ng-cloak], .ng-cloak {
display: none !important;
}
内容总结
以上是互联网集市为您收集整理的javascript – 防止初始显示角度模板全部内容,希望文章能够帮你解决javascript – 防止初始显示角度模板所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。