.state('hello', { url: '/hello/{name}/{id}', templateUrl: 'views/name.html', }) conrtoller1:$state.go('hello',{name:'小明'},{id:1}) controller2:$stateParams.name和.id可以拿到controller1中传过来的值
推荐把filter写在另一个js文件中,然后在你的页面中引用。可以是下面这样:
angular.module('myapp').filter('reverse', function() {
return function(items) {
if(items) {
return items.slice().reverse();
} else {
return [];
}
}
}).filter('slice', function () {
return function (inputArr, start, end) {
var resultArr = [];
if (!angular.isArray(inputArr)) { return inputArr; }
if (start < 0) { start = 0; }
if (end > inputArr.length) { end = inputArr.length; }
for (var i = start; i < end; ++i) {
resultArr.push(inputArr[i]);
}
return resultArr;
};
});