私は、角型プロジェクト、app.js、そしてコントローラのmain.jsを持っています。私はディレクティブを作成したいのですが、app.jsまたはmain.jsで作成するかどうかにかかわらず、2つの異なるエラーが発生しますが、いずれかの方法では動作しません。ディレクティブを作成すると[ng:areq]エラーが発生する
は、これは私のapp.js(まだありませんディレクティブ)
var myapp = angular
.module('nombre_proyectoApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ngDialog'
]);
myapp.config(function ($routeProvider,$sceDelegateProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
//templateUrl: '/dms/static/nombre_proyecto/views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
.when('/about', {
templateUrl: 'views/about.html',
//templateUrl: '/dms/static/nombre_proyecto/views/about.html',
controller: 'AboutCtrl',
controllerAs: 'about'
})
.otherwise({
redirectTo: '/'
});
$sceDelegateProvider.resourceUrlWhitelist(['self','http://*.leroymerlin.es/**']);
});
であり、これは私のmain.js(まだありませんディレクティブ)
myapp.controller('MainCtrl', ['$scope','$http','ngDialog','$sce', function ($scope, $http, ngDialog, $sce) {
$scope.Math = window.Math;
$scope.seleccion = 'all';
$scope.productos = [];
$http.get('productos.json').then(function(response){
$scope.productos = response.data;
});
$scope.select = function (s){
$scope.seleccion = s;
};
}]);
は今、これはうまく動作しますが、あります
:私はその後、私はこのエラーを取得するこのmyapp.directive('listado', function(){
return {
restrict: 'E',
compile: function(element, attrs){
var filtro = attrs.filtro || 'all';
var productos = attrs.productos;
var htmlText = '
<ul>
<li class="producto col-md-12" ng-repeat="producto in '+ productos +'" ng-if="(producto.group == '+ filtro +') || ('+ filtro +' == \'all\')">
<div class="col-md-4">
<img src="{{producto.imgUrl}}" alt="foto">
</div>
<div class="col-md-5">
<p class="titulo">{{producto.title}}</p>
<p class="verdeLM"><a href="http://www.leroymerlin.es/fp/{{producto.ref}}">Ref. {{producto.ref}}</a></p>
<p class="gris">{{producto.description}}</p>
</div>
<div class="col-md-3 text-right">
<div class="precio">{{Math.floor(producto.price)}},<sup>{{decimales(producto.price)}} €</sup></div>
<a class="btnVerProd" href="http://www.leroymerlin.es/fp/{{producto.ref}}" target="_blank" ng-click="verProd(producto.ref)">Ver producto</a>
</div>
</li>
</ul>';
element.replaceWith(htmlText);
}
};
});
ようmain.jsにディレクティブを追加します
angular.js:13424エラー:[NG:AREQ]引数が 'MainCtrl' 関数ではないので、未定義 http://errors.angularjs.org/1.5.3/ng/areq?p0=MainCtrl&p1=not%20aNaNunction%2C%20got%20undefined
を持って、私はapp.jsに入れてみてください、そして、私はこれを取得他のエラー:
angular.js:68不明なエラー:[$インジェクター:modulerr]: エラー:[$インジェクター:nomod]モジュールのnombre_proyectoApp」は利用できない原因にモジュールnombre_proyectoAppをインスタンス化に失敗しました!モジュール名のスペルが間違っているか、モジュール名を読み込めませんでした。モジュールを登録する場合は、依存関係を2番目の引数として指定するようにしてください。すべてのヘルプははるかに高く評価されるだろう。この
<listado productos="productos"></listado>
ようmain.htmlとで http://errors.angularjs.org/1.5.3/ $インジェクター/ nomod?P0 = nombre_proyectoApp
私が呼んでいるディレクティブ..