下面的两个脚本语句单独运行时可以正常工作,但当它们合并在一起时,会导致错误:[$injector:unpr]未知提供者: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>
myApp
。创建两个不同的模块。空数组是用来传递依赖到其他模块的地方。请参考这里http://docs.angularjs.org/guide/module - elclanrs