gpt4 book ai didi

javascript - 指令丢失范围内的 Ng-repeat

转载 作者:行者123 更新时间:2023-11-30 16:46:10 25 4
gpt4 key购买 nike

我在指令范围内遇到问题

尝试以下链接(尝试第二个和第三个输入框,它们应该共享相同的 ng-model)

https://output.jsbin.com/rudimihuha

基本上我在其中有一个指令和一个 ng-rpeat,不知何故范围在 ng-repeat 中丢失了,它这样做的任何原因是什么?

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
<!--
Created using JS Bin
http://jsbin.com

Copyright (c) 2015 by anonymous (http://jsbin.com/rudimihuha/1/edit)

Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex">
<title>JS Bin</title>
</head>
<body ng-app="MyApp">
<test></test>
<script>
var myApp = angular.module('MyApp', []);
console.log('hit');

myApp.directive('test', function () {
return {
restrict: 'E',
template: "<div>inertanl - {{formResult}} <input type=\"text\" ng-model=\"formResult\"> <div> <div ng-repeat=\"(key, value) in ['test', 'test2']\"> <input type=\"text\" ng-model=\"formResult\"> </div></div>",
replace: true,
scope: {
ngModel : '='
}
};
});
</script>
<script src="https://static.jsbin.com/js/render/edit.js?3.30.3"></script>
<script>jsbinShowEdit && jsbinShowEdit({"static":"https://static.jsbin.com","root":"https://jsbin.com"});</script>
<script src="https://static.jsbin.com/js/vendor/eventsource.js?3.30.3"></script>
<script src="https://static.jsbin.com/js/spike.js?3.30.3"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-1656750-34', 'jsbin.com');
ga('require', 'linkid', 'linkid.js');
ga('require', 'displayfeatures');
ga('send', 'pageview');

</script>

</body>
</html>

最佳答案

根据 Angular 文档 ng-repeat 创建一个新范围。

您可以在这里阅读更多相关信息:https://docs.angularjs.org/api/ng/directive/ngRepeat

关于javascript - 指令丢失范围内的 Ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199416/

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