我创建了项目asp.mvc并添加了angularjs,添加了fabricjs https://codepen.io/michaeljcalkins/pen/Imupw
现在我在控制台中捕获错误: Error:$injector:unpr未知提供者: FabricProvider <- Fabric <- ExampleCtrl
我的app.js:
var app = angular.module('myApp', ['ngRoute', 'ngResource']);
angular.module('example', [
'common.fabric',
'common.fabric.utilities',
'common.fabric.constants'
]).controller('ExampleCtrl', ['$scope', 'Fabric', 'FabricConstants', 'Keypress', function ($scope, Fabric, FabricConstants, Keypress) {
$scope.fabric = {};
$scope.FabricConstants = FabricConstants;
//
// Creating Canvas Objects
// ================================================================
$scope.addShape = function (path) {
$scope.fabric.addShape('http://fabricjs.com/assets/15.svg');
};
$scope.addImage = function (image) {
$scope.fabric.addImage('http://stargate-sg1-solutions.com/blog/wp-content/uploads/2007/08/daniel-season-nine.jpg');
};
$scope.addImageUpload = function (data) {
var obj = angular.fromJson(data);
$scope.addImage(obj.filename);
};
//
// Editing Canvas Size
// ================================================================
$scope.selectCanvas = function () {
$scope.canvasCopy = {
width: $scope.fabric.canvasOriginalWidth,
height: $scope.fabric.canvasOriginalHeight
};
};
$scope.setCanvasSize = function () {
$scope.fabric.setCanvasSize($scope.canvasCopy.width, $scope.canvasCopy.height);
$scope.fabric.setDirty(true);
delete $scope.canvasCopy;
};
//
// Init
// ================================================================
$scope.init = function () {
$scope.fabric = new Fabric({
JSONExportProperties: FabricConstants.JSONExportProperties,
textDefaults: FabricConstants.textDefaults,
shapeDefaults: FabricConstants.shapeDefaults,
json: {}
});
};
$scope.$on('canvas:created', $scope.init);
Keypress.onSave(function () {
$scope.updatePage();
});
}]);在我的项目中查找"FabricProvider“没有结果。
发布于 2017-10-10 16:58:55
根据github中提供的代码,您应该在_Layout.cshtml页面中包含如下顺序的脚本包
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/angular")
@Scripts.Render("~/bundles/fabric" )
@Scripts.Render("~/bundles/angularapp")您应该从_Layout文件中删除重复的模块和控制器,如下所示
<body ng-app="example" ng-controller= "ExampleCtrl">
因为您在index.cshtml中也使用相同的模块和控制器。
在布局页面中,您应该在捆绑包@Scripts.Render("~/bundles/angularapp")之前包含捆绑包@Scripts.Render("~/bundles/fabric" ),因为app.js依赖于捆绑包~/bundles/fabric中包含的fabric.js的结构依赖项
发布于 2017-10-11 15:24:34
尼拉德里!我重新启动了VS,然后把它拿出来!
非常感谢!!
https://stackoverflow.com/questions/46649829
复制相似问题