gpt4 book ai didi

javascript - 在 angularJs 中创建指令

转载 作者:行者123 更新时间:2023-11-28 12:26:38 26 4
gpt4 key购买 nike

我正在尝试在 angularJS 中创建一个指令。但这不起作用。我所做的如下。

我的主要 html 代码

<body ng-app="birthdayToDo" ng-controller="main">
<h1>Hello Plunker!</h1>
<myCustomer></myCustomer>
</body>

我的Js代码:

var app = angular.module('birthdayToDo', []);

app.controller('main', function($scope) {
$scope.employees=[
{
Name:"Amit",
Email:"Amit@gmail.com"
},
{
Name:"Ajay",
Email:"Ajay@gmail.com"
},
{
Name:"Rahul",
Email:"Rahul@gmail.com"
},
{
Name:"Aakash",
Email:"Aakash@gmail.com"
},
{
Name:"Rohit",
Email:"Rohit@gmail.com"
},
];

});
app.directive('myCustomer', function() {
var directive = {};

directive.restrict = 'E'; /* restrict this directive to elements */
directive.templateUrl = "directiveFile.html";

return directive;
});

我的directiveFile.html代码

<table>
<tr>
<td>SNo.</td>
<td>Name</td>
<td>Email</td>
</tr>
<tr ng-repeat="employee in employees">
<td>{{$index+1}}</td>
<td>{{employee.Name}}</td>
<td>{{employee.Email}}</td>
</tr>
</table>

但是这段代码不起作用。我做错了什么。

<强> Plunker link

最佳答案

您有 2 个命名选项:

1.

app.directive('myCustomer', function()
<my-customer> </my-customer>

2.

app.directive('mycustomer', function()
<mycustomer> </mycustomer>

关于javascript - 在 angularJs 中创建指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27817818/

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