我确信以前曾经问过,但我找不到答案.
我有一个AngularJS脚本,它从数据库中提取,然后渲染到内容.一切都正常工作,除了几个地方,我试图将一些单词与它们之间的新行连接起来.
**in the script.js**
groupedList[aIndex].CATEGORY = existingCategory+'\n'+thisCategory;
groupedList[aIndex].CATEGORY = existingCategory+'<br>'+thisCategory;
Run Code Online (Sandbox Code Playgroud)
如果我使用上面代码的第一行,我没有看到任何内容,但在redered html中没有新行.如果我使用第二行,则<br>呈现为文本,输出如下所示:
Instinct<br>Media
Run Code Online (Sandbox Code Playgroud)
代替
Instinct
Media
Run Code Online (Sandbox Code Playgroud)
我可以发布完整的脚本,如果这将有所帮助,但我猜我有一些简单的东西,我只是没有看到.
更新 这里是完整的js
function qCtrl($scope, $filter, $http, $timeout){
$scope.getCategories = function(){$http.post('quote.cfc?method=getCategories').success(function(data) { $scope.categories = data; }); }
$scope.getClassifications = function(){$http.post('quote.cfc?method=getClassifications').success(function(data) { $scope.classifications = data; }); }
$scope.getIndustries = function(){$http.post('quote.cfc?method=getIndustries').success(function(data) { $scope.industries = data; }); }
$scope.getKeywords = function(){$http.post('quote.cfc?method=getKeywords').success(function(data) { $scope.keywords = data; }); }
$scope.getSources = function(){$http.post('quote.cfc?method=getSources').success(function(data) { $scope.sources = data; }); }
$scope.getAllQuotes = function(){$http.post('quote.cfc?method=getAllQuotesJoined').success(function(data) { $scope.allQuotes = data; }); …Run Code Online (Sandbox Code Playgroud) 我有剩下的api惠特/n代码,可以用<br>标签替换angular 6
这是我的代码:
{{x.deskripsi}}
Run Code Online (Sandbox Code Playgroud)
我尝试使用https://www.npmjs.com/package/angular-nl2br-filter
但是我不知道如何与{{}}标签内部绑定一起使用
我尝试使用此代码
<p ng-bind-html="x.deskripsi | nl2br"></p>
Run Code Online (Sandbox Code Playgroud)
但不起作用
有什么帮助吗?
之前感谢
我有一个字符串,其中包含要由 Angular 6 上的 ngx-markdown 服务呈现的 Markdown 内容主体。该字符串存储在 Google Firestore 数据库中。所以我打算使用“\n”字符将内容分解成单独的行,然后再由 ngx markdown 服务处理。
第一个有序列表项\n2. 另一个项目\n * 无序子列表。\n1. 实际数字无关紧要,只是它是一个数字\n 1. 有序子列表\n4. 还有另一个项目。\n\n 您可以在列表项目中正确缩进段落。注意上面的空行和前导空格(至少一个,但我们在这里也使用三个来对齐原始 Markdown)。\n\n 要在没有段落的情况下换行,您需要使用两个尾随空间。\n 请注意,此行是单独的,但在同一段落内。\n(这与典型的 GFM 换行行为相反,其中不需要尾随空格。)\n\n\n* 无序列表可以使用星号\n- 或减号\n+ 或加号
如何用新行手动替换字符串中的“\n”字符?我以前在 C# 和 VB.NET 中使用 Environment.NewLine() 来完成这项工作 - TypeScript 有等效的方法吗?
因此,我尝试做一些非常简单的事情,但遇到了麻烦。我有一个String变量,在该变量中,我想设置换行符,以便文本的某些部分转到新行。
我尝试过的
title: string = "My \n Title";
title: string = "My\ Title";
title: string = "My\
Title";
title: string = "My" + "\n" + "Title";
Run Code Online (Sandbox Code Playgroud)
我尝试了许多变体,但无法正常工作。我是不是很傻并且缺少一些显而易见的东西?
不是重复的,因为我尝试过,<br/>并且没有用。
更新:
像这样在浏览器HTML中打印变量 {{title}}