angular.js file
define(['angular'],function(){
angular.module("todosa",[]).controller("todosAngular",function($scope){
$scope.sum=new Array();
var fn=function(){
if($scope.sum.length<10 ){
if($scope.arr!=="" && $scope.arr!==undefined){
$scope.sum.unshift($scope.arr);
$scope.arr="";
}
}else{
alert("已经10个了,不能在增加了。");
$scope.arr="";
}
}
$scope.todosAclick=function(){
fn();
};
$scope.todosAremove=function(){
$scope.sum=[];
$scope.arr="";
};
$scope.todosAre=function(s){
$scope.sum.splice(s,1);
};
$scope.akeydown=function(e){
if(e.keyCode==13) fn();
};
});
})
main.js,reuiqre entry file
require.config({
baseUrl:"../js/",
paths:{
'jquery':'lis/jquery.min',
'avalon':'lis/avalon.min',
'angular':'lis/angular.min'
}
});
require(['todosAngular','todosjs','todosAvalon','todosJquery'],function(){
});
R.js
({
baseUrl:".",
name:'todosmain',
paths:{
'jquery':'lis/jquery.min',
'avalon':'lis/avalon.min',
'angular':'lis/angular.min'
},
excludeShallow:["angular","avalon","jquery"],
out:"todos-Set.js"
})
Error message
Error: [$injector:unpr] http://errors.angularjs.org/1.4.3/$injector/unpr?p0=eProvider%20%3C-%20e%20%3C-%20todosAngular
at Error (<anonymous>)
at http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:6:416
at http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:40:375
at Object.d [as get] (http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:38:364)
at http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:40:449
at d (http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:38:364)
at Object.e [as invoke] (http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:39:124)
at P.instance (http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:80:122)
at S (http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:61:199)
at g (http://127.0.0.1:4000/sunshine/add/js/lis/angular.min.js:54:384)
This is just a small demo of todos written by me. I want to try packaging it with r.js, but angular keeps saving it. There were almost no errors before packaging using r.js.
demo address:
for packaging
after packaging
1. I probably know where your error is. Looking at the error message, it should be a dependency injection problem. You need to inject the dependent things into your controller. Like the $scope above, it needs to be injected into the control. Yes, it should be written like this: App.controller("CtrlName",["$scope",function($scope){...}]) Because if not, its structure will be destroyed when packaging, so it will Error report; I am replying to you on my mobile phone, which is inconvenient. If I have time, I will give you a more detailed explanation on my computer.
(I don’t know why the characters are always garbled after modification...)
Before you package with r.js, use ngAnnotate to handle the dependency injection syntax (so you don’t need the array mode syntax). Of course, it is best to use a build tool to automate this process.