如何解决angularjs中的$ injector错误?

时间:2019-01-28 04:40:29

标签: javascript angularjs

我是angularjs的新手,我尝试使用一些教程来创建简单的页面。一个页面用于用户输入html,另一个页面用于if else语句。我在控制台中始终收到以下错误消息:“ [$ injector:unpr] ”。 index.html

<body ng-app="ngCribs" ng-controller="cribsController">
<div class="container">     
                <div class="row price-form-row" ng-if="!addListing">
                    <span class="input-group-addon">Min Price</span>
                    <select name="minPrice" id="minPrice" [ng-model]="priceInfo.min" class="form-control">
                      <option value="100000">$100,000</option>
                      <option value="200000">$200,000</option>
                      <option value="300000">$300,000</option>
              </select>
                  </div>          
                <span class="input-group-addon">Max Price</span>
                    <select name="maxPrice" id="maxPrice" ng-model="priceInfo.max" class="form-control">
                      <option value="100000">$100,000</option>
                      <option value="200000">$200,000</option>
                      <option value="300000">$300,000</option>
                     </select>
     <div class="container">
      <div class="col-sm-4" 
        ng-repeat="crib in cribs | cribsFilter:priceInfo | orderBy: '-id'">          
              <i class="glyphicon glyphicon-tag"></i> {{crib.price | currency}} <i class="glyphicon glyphicon-home"></i> {{crib.address}} 
                <span class="label label-primary label-sm">{{crib.type}}</span></div>             
 </body>
  <script src="app.js"></script>
  <script src="scripts/cribsFilter.js"></script>
</html>   

cribsFiler.js

angular
    .module('ngCribs')
    .filter('cribsFilter', function() {
    return function(listings, priceInfo) {
    var filtered = [];
    var min = priceInfo.min;
    var max = priceInfo.max;
     angular.forEach(listings, function(listing) {
      if(listing.price >= min && listing.price <= max) {
      filtered.push(listing);
                }
            });
       return filtered;
        }
    });

CribsController.js

angular
.module('ngCribs')
.controller('cribsController',function($scope, cribsFactory){

$scope.priceInfo ={
    min:0,
    max:1000000
}
$scope.cribs;
cribsFactory.getCribs().then(function(data){
    $scope.cribs = data.data;
});
(function(error){
    console.log(error);
});
});

App.js

angular.module('ngCribs',['ui.bootstrap']);

1 个答案:

答案 0 :(得分:0)

我不确定自己没有看到public class ScanActivity extends AppCompatActivity { private static final int REQUEST_CODE_SCAN_RESULT = 47; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scan); // Show scanning screen when ScanActivity first time created showScanningScreen(); } private void showScanningScreen() { IntentIntegrator scanIntegrator = new IntentIntegrator(ScanActivity.this); scanIntegrator.setOrientationLocked(false); scanIntegrator.initiateScan(); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == REQUEST_CODE_SCAN_RESULT) { // Show scanning screen when users press back key from `ScanResultActivity`. showScanningScreen(); } else { IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if (scanResult != null) { String strResult = scanResult.getContents(); if (strResult != null) { Intent iii = new Intent(ScanActivity.this, ScanResultActivity.class); iii.putExtra("scan_result", strResult); startActivityForResult(iii, REQUEST_CODE_SCAN_RESULT); } else { // Exit/finish current backstack when users press back key on ScanActivity onBackPressed(); } } else { super.onActivityResult(requestCode, resultCode, data); } } } @Override public void onBackPressed() { // Override this function to finish current backstack (default behavior is push current activity from backstack) finishAffinity(); } } ,但是鉴于其他所有情况,我可以做出以下猜测:您可能应该添加脚本标记来引用app.js:-)