我正在关注这个视频教程(相同的文本版本).我遵循完全相同的代码,我收到此错误:
错误TS2339:类型'EmployeeService'上不存在属性'getEmployees'
我看着在互联网上,堆栈溢出走访了许多问题,如这个,这个,这个和这个,和许多其他人的问题打开相关GitHub上此错误.
服务:
//import statements go here ...
@Injectable()
export class EmployeeService {
private listEmployees: Employee[] = [
{
//just to avoid longer code, deleted dummy data.
},
];
getEmployees(): Employee[] {
return this.listEmployees; //ERROR in src/app/employees/list-employees.component.ts(14,44)
}
}
Run Code Online (Sandbox Code Playgroud)
组件类:
//import statements
@Component({
selector: 'app-list-employees',
templateUrl: './list-employees.component.html',
styleUrls: ['./list-employees.component.css']
})
export class ListEmployeesComponent implements OnInit {
employees: Employee[];
constructor(private _EmployeeService: EmployeeService) { }
ngOnInit() {
this.employees = …Run Code Online (Sandbox Code Playgroud) 我正在尝试图表。我通过cli创建了新的角度应用程序,并安装了highcharts和highcharts-angular。我从他们的github页面复制了代码。在第一次运行中,我遇到以下错误。
ERROR in node_modules/highcharts/highcharts.d.ts(128972,17): error TS2304: Cannot find name 'PlotNetworkDataLabelsFormatterCallbackFunction'.
node_modules/highcharts/highcharts.d.ts(128982,21): error TS2304: Cannot find name 'PlotNetworkDataLabelsFormatterCallbackFunction'.
node_modules/highcharts/highcharts.d.ts(128987,19): error TS2304: Cannot find name 'PlotNetworkDataLabelsTextPath'.
node_modules/highcharts/highcharts.d.ts(128992,15): error TS2304: Cannot find name 'PlotNetworkDataLabelsTextPath'.
node_modules/highcharts/highcharts.d.ts(136653,17): error TS2304: Cannot find name 'PlotPackedBubbleDataLabelsFormatterCallbackFunction'.
node_modules/highcharts/highcharts.d.ts(136658,15): error TS2304: Cannot find name 'PlotPackedBubbleDataLabelsTextPath'.node_modules/highcharts/highcharts.d.ts(237720,14):
error TS2304: Cannot find name 'SeriesOrganizationNodesLayoutValues'.
Run Code Online (Sandbox Code Playgroud)
我使用以下方法从npm安装了highcharts
npm install highcharts-angular --save
和
npm install highcharts-保存
然后我在app.module.ts中导入了HighchartsChartModule并从highcharts-angular中导入了数组。在app.component.ts和app.component.html中,我从其github页面添加了示例代码。
我遇到了错误。我应该安装任何插件或依赖项吗?
我需要使用jQuery动态添加一些元素。因此,我在互联网上查找后发现了这一点。当单引号内包含简单的html元素时,它很好并且可以工作。我需要在jQuery中使用剃刀语法。
我知道jQuery是用户端,而剃须刀是服务器端。它们不能组合在一起。我在这里问是因为我需要知道如何实现这一目标。
我无法使用的jQuery如下所示:
<script type="text/javascript">
$(document).ready(function () {
$(document).on("click", ".btnPlus", function () {
var html = '<div class="form-group">'+
'@Html.LabelFor(model => model.transaction_item, "transaction_item", htmlAttributes: new { @class = "control-label col-md-2" })'+
'<div class="col-md-4">'+
'@Html.DropDownList("transaction_item", null, htmlAttributes: new { @class = "form-control" })'+
'@Html.ValidationMessageFor(model => model.transaction_item, "", new { @class = "text-danger" })'+
'</div>'+
'<div class="col-md-6"><input type="button" class="BtnPlus" value="+" /></div>'+
'</div>'
$("#trItem").append($(html))
};
});
Run Code Online (Sandbox Code Playgroud)
我的目标类似于本教程 -动态添加元素。在这里,我在单击按钮时添加了标签和下拉菜单。我该如何实现?
我在 Razor 视图页面中使用了 `@Html.Textbox("searchString")。我需要这个文本框的值
@Html.ActionLink("View Items", "Index", new { id = item.transaction_id, searchString = "Value of textbox"}).
Run Code Online (Sandbox Code Playgroud)
当然,html 操作链接中的搜索字符串部分现在不起作用,但我需要这个,因为我有根据搜索字符串工作的特定路线。
如何将文本框的值传递给操作链接?
我试过的是
<script type = "text/javascript">
var value = document.getElementbyID("searchString").Text;
var link = @Html.ActionLink("View Items", "Index", new { id = item.transaction_id, searchString = -1});
link.replace(-1,value);
</script>
Run Code Online (Sandbox Code Playgroud)
仍然没有运气。我了解 Razor 在服务器端渲染。
更新
我在视图顶部有以下文本框:
@using (Html.BeginForm("Index", "trans_junction", FormMethod.Get))
{
<p>
Request No: @Html.TextBox("searchString")
<span><input type="submit" value="Search Request" /></span>
</p>
}
Run Code Online (Sandbox Code Playgroud)
此文本框是用户可以在其中搜索项目的搜索框。
有一个操作链接如下:
@Html.ActionLink("View Items", "Index", …Run Code Online (Sandbox Code Playgroud) 我有以下HTML代码.它由Razor引擎生成.这是动态的.我的意思是下拉中的元素数量可能因用户而异.我需要使用新的id和新名称将此下拉列表完全复制到相同的下拉列表下方.我看过这里,这里,这里和这里.以下是我的HTML.我在代码中添加了注释以获得更多说明.
<!-- the entire section with id and name template needs to be copied -->
<div id="template" name="template" class="form-group unique">
<label class="control-label col-md-2" for="Course">Course</label>
<!-- the drop down below has id and name as Course[0].Title
I need to increment index inside [] -->
<div class="col-md-10">
<select class="form-control drop valid" id="Course[0].Title" name="Course[0].Title">
<option value="1">Statistics</option>
<option value="2">Trigonometry</option>
<option value="3">Biology</option>
<option value="4">Neurology</option>
<option value="5">Applied</option>
<option value="6">Theoretical</option>
</select>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
现在我提出了以下jQuery代码.它只复制一次然后停止工作.我检查了控制台,没有错误.带有注释以澄清的javascript代码如下.
< script src = "~/Scripts/jquery-1.10.2.min.js" …Run Code Online (Sandbox Code Playgroud)我正在使用Entity Framework学习ASP.Net MVC.我想得到最后保存记录的ID.我已经检查了这个,当你想获得最近保存的记录的id时,接受的答案正常.我需要两天前可能保存的记录.
我该如何检索?
asp.net-mvc ×3
javascript ×3
razor ×3
angular ×2
asp.net ×2
c# ×2
jquery ×2
css ×1
highcharts ×1
html ×1
typescript ×1