gpt4 book ai didi

javascript - AngularJS Unknown Provider (filterProvider) 错误

转载 作者:行者123 更新时间:2023-11-29 14:53:45 25 4
gpt4 key购买 nike

下面的两个脚本语句独立工作,但是当它们组合在一起时会导致错误:[$injector:unpr] Unknown provider: searchNameFilterProvider <- searchNameFilter 谁能解释为什么会这样?

第一段

Find Person: <input type="text" ng-model="myName">
<ul ng-init="people = ['Diarmuid','Aine','Dave','Declan']">
<li ng-repeat="person in people | filter:myName">{{ person | searchName}}</li>
</ul>

<script>
var app = angular.module('myApp',[]);
app.filter('searchName',function(){
return function (input){
return input + '!';
}
})
</script>

第二段

<div ng-controller="myCtrl">
<button ng-click="myFunc()">Hello World Button</button>
</div>

<script>

var app = angular.module('myApp',[]);
app.controller('myCtrl',function ($scope) {

$scope.myFunc = function () {
console.log('Hello world!');
};
});

</script>

最佳答案

<div ng-app="myApp">
<script src="Scripts/Angular.js" type="text/javascript"></script>
Find Person:
<input type="text" ng-model="myName">
<ul ng-init="people = ['Diarmuid','Aine','Dave','Declan']">
<li ng-repeat="person in people | filter:myName">{{ person | searchName}}</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('searchName', function () {
return function (input) {
return input + '!';
};
});
</script>
<div ng-controller="myCtrl">
<button ng-click="myFunc()">
Hello World Button</button>
</div>
<script>

var app = angular.module('myApp');
app.controller('myCtrl', function ($scope) {

$scope.myFunc = function () {
console.log('Hello world!');
};
});

</script>

关于javascript - AngularJS Unknown Provider (filterProvider) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21443702/

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