我已经写了一段代码,它接受一些文本输入,并删除了text.The代码中的'#‘标记,运行良好。但最初当页面加载时,我得到的是'{{textWithHashes | textWithoutDashes}}'.This不是很有吸引力。我尝试过使用ng-.This,但我仍然无法隐藏它。有没有人可以告诉我为什么它不工作,是否有更好的方法隐藏它。
Html文件:
<!DOCTYPE html>
<html>
<head>
<title>Removing the delimiters from the Text</title>
<script src="js/angular.min.js"></script>
<script src="js/appModule1.js"></script>
</head>
<body ng-app="appModule" ng-controller="appModuleCtrl">
<input type="text" ng-model="textWithHashes">
<!--The next line will give the text without the hash tags-->
<label ng-cloak>{{textWithHashes | textWithoutDashes}}</label>
</body>
</html>Javascript文件:
var appModule=angular.module('appModule',[]);
appModule.filter('textWithoutDashes',function(){
return function(text){
return text.split('#').join(' ');
}
});
appModule.controller('appModuleCtrl',function(){
});发布于 2016-02-03 14:31:14
您可以使用ng-bind并过滤控制器中的文本(这也是performance wize的建议):
<label ng-bind="textWithHashes"></label>
在你的控制器中:
appModule.controller('appModuleCtrl',function($scope, $filter){
$filter('textWithoutDashes')($scope.textWithHashes);
});发布于 2016-02-03 14:48:00
根据ng-cloak文档( https://docs.angularjs.org/api/ng/directive/ngCloak ),您必须在head标记中添加此css:
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
}https://stackoverflow.com/questions/35169958
复制相似问题