gpt4 book ai didi

javascript - 在 Angular 中处理事件

转载 作者:行者123 更新时间:2023-11-28 15:08:42 25 4
gpt4 key购买 nike

我正在使用 Angular 代码的使用 Angular js脚本,此代码不是 在 html 页面中不返回任何内容我尝试了多次但也不返回 没有任何想法或帮助运行此代码

/// <reference path="angular.min.js" />
//var myApp = angular.module("myModule", []);

myApp = angular
.module("mymodule", [])
.controller("mycontroller", function ($scope) {
var tecnologies = [
{ name: "c#", likes: 0, dislikes: 0 },
{ name: "asp.net", likes: 0, dislikes: 0 },
{ name: "sqlserver", likes: 0, dislikes: 0 },
{ name: "Angulaer js", likes: 0, dislikes: 0 },
];
$scope.tecnologies.tecnologies;
$scope.incrementlikes=function(tecnologyy)
{
tecnologyy.likes++;
}
$scope.incrementdislikes = function (tecnologyy) {
tecnologyy.dislikes++;
}
});

标记:

<!DOCTYPE html>
<html xmlns="xmlns= http //www.w3.org/1999/xhtml">
<head>

<title></title>
<!--<script src="scripts/angular.min.js"></script>-->
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular.js"></script>
<!--<script src="scripts/Script.js"></script>-->
<script src="scripts/JavaScript9.js"></script>
<!--<script src="scripts/angular.js"></script>-->
<title></title>
</head>
<body ng-app="mymodule">
<div ng-controller="mycontroller">
<table>
<tr>
<th>Name</th>
<th>likes</th>
<th>dislikes</th>
<th>Likes/dislikes</th>
</tr>
<tbody>
<tr ng-repeat="tecnolgy in tecnologies">
<td>{{tecnolgy.name}}</td>
<td>{{tecnolgy.likes}}</td>
<td>{{tecnolgy.dislikes}}</td>
<td>
<input type="button" value="Like" ng-click="incrementlikes(tecnolgy)">
<input type="button" value="disLike" ng-click="incrementdislikes(tecnolgy)">
</td>
</tr>
</tbody>
</table>
</div>


</body>
</html>

最佳答案

更改此:

$scope.tecnologies.tecnologies;

对此:

$scope.tecnologies = tecnologies;
<小时/>

虽然我注意到了一些提示:

  1. 两个 Angular 库加载在头部。
  2. 最好缓存模块,然后分配 Controller 。
  3. 您尚未绑定(bind)/分配实际数组。
<小时/>

指针:

1.

<script src="scripts/angular.min.js"></script>
<!--<script src="scripts/angular.js"></script>-->

2,3。

var myApp = angular.module("mymodule", []);

myApp.controller("mycontroller", function($scope) {
var tecnologies = [
{ name: "c#", likes: 0, dislikes: 0 },
{ name: "asp.net", likes: 0, dislikes: 0 },
{ name: "sqlserver", likes: 0, dislikes: 0 },
{ name: "Angulaer js", likes: 0, dislikes: 0 },
];
$scope.tecnologies = tecnologies;
$scope.incrementlikes = function(tecnologyy) {
tecnologyy.likes++;
};
$scope.incrementdislikes = function(tecnologyy) {
tecnologyy.dislikes++;
};
});

关于javascript - 在 Angular 中处理事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37679342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com