我正在使用AngularJS创建应用程序,并且我是新手。我已经创建了一个公共页面,用于使用其单独的控制器进行搜索并且工作正常,但是现在我想将该页面作为用户控件包含在其他页面中。
我的搜索页面就像
<div class="input-group ex col-md-3" ng-app="searchApp" ng-controller="MainSearchController">
.......
.......//My code here
</div>
我的搜索控制器是:
var sApp=angular.module("searchApp",[]);
sApp.controller("MainSearchController", function($scope){
$scope.Merchants={};
var DEMerchantInfo = JSON.parse(localStorage.getItem("DEMerchantInfo"));
if(DEMerchantInfo == null || DEMerchantInfo == undefined){
DEMerchantInfo = new Array;
}
$scope.Merchants=DEMerchantInfo;
$scope.Search=function(){
var DEMerchantInfo = JSON.parse(localStorage.getItem("DEMerchantInfo"));
if(DEMerchantInfo == null || DEMerchantInfo == undefined){
DEMerchantInfo = new Array;
}
$scope.Merchants=DEMerchantInfo;
}
});
我在其他页面中使用搜索页面,例如:
<body class="sidebar-mini" ng-app="MerchantApp">
<div class="search-panels col-lg-4 col-md-4 col-xs-10">
<div ng-include src=" 'search.html' "></div>
</div>
</body>
但这对我不起作用。它给的错误。
Error: [ng:areq] http://errors.angularjs.org/1.5.7/ng/areq? p0=MainSearchController&p1=not%20a%20function%2C%20got%20undefined O/<@file:///.....
因此,任何人都可以建议我如何实现这一目标。
这是搜索页面模板的外观:
<div class="input-group ex col-md-3" ng-controller="MainSearchController">
<!-- My code here -->
</div>
注意,我已从ng-app="searchApp"
局部删除。在您的应用中,您需要将其添加ng-app="searchApp"
到某个父容器中,例如body
或html
。
然后,您将需要MerchantApp
像这样进行配置:
angular.module('MerchantApp', [
// some other module dependencies
'searchApp'
])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句