gpt4 book ai didi

javascript - 带 A 限制的指令的属性

转载 作者:行者123 更新时间:2023-12-02 14:53:27 25 4
gpt4 key购买 nike

考虑一个具有隔离范围(对象)的指令,并限制 A,我如何传递它们的属性?

例如,当涉及到限制 E 时,如果范围等于 {attr : '@'} ,则该指令将被调用为 。

最佳答案

属性的传递方式与 E 类型指令的传递方式相同。

引用:http://plnkr.co/edit/T2R91F0iR9GfttSav9Zq?p=preview

//HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example12-production</title>


<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<script src="script.js"></script>



</head>
<body ng-app="docsSimpleDirective">
<div ng-controller="Controller">
<div my-customer customer="customer" testv="Hello"></div>
</div>
</body>
</html>

//JS
(function(angular) {
'use strict';
angular.module('docsSimpleDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.customer = {
name: 'Naomi',
address: '1600 Amphitheatre'
};
}])
.directive('myCustomer', function() {
return {
restrict: 'A',
scope: {
customer:'=',
testv: '@'
},
template: 'Name: {{customer.name}} Address: {{customer.address}} - {{v1}}',
link: function(scope, element, attrs) {
console.log(attrs);
scope.v1=attrs.testv;
}
};
});
})(window.angular);

关于javascript - 带 A 限制的指令的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006995/

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