cordova ionic app似乎会加载控制器两次。

10 浏览
0 Comments

cordova ionic app似乎会加载控制器两次。

我在使用Cordova(5.3.3)创建的应用程序中遇到了一些问题,使用的是ionic(1.6.5)和angular js,并且构建用于iOS和Android。

我有一个菜单项,当我点击它时,应该加载下一个带有其他菜单项的状态。然而,似乎它先加载下一个状态而没有动画,然后再加载带有动画的状态,导致“卡顿”效果。最好在这里上传的视频中展示:https://www.youtube.com/watch?v=YCEQeqFyNl4&feature=youtu.be

我想知道是否有人知道这里可能出现的问题以及我应该从哪里开始查找,或者是否已知有关此问题的错误?

任何帮助将不胜感激!

// 控制器

.controller('ProgramCtrl', ['$scope', 'FacProgram',

function($scope, FacProgram) {

$scope.refresh = function() {

FacProgram.refresh()

.finally(function() {

$scope.$broadcast('scroll.refreshComplete');

});

};

$scope.temp_articles = function() {

return FacProgram.all();

};

}

])

.controller('ProgramDetailCtrl', ['$scope', '$stateParams', 'FacProgram',

function($scope, $stateParams, FacProgram) {

$scope.art = FacProgram.get($stateParams.programId);

}

])

// 工厂在另一个js文件中:

.factory('FacProgram', ['$http', '$q', 'FacJson',

function($http, $q, FacJson) {

var temp_articles = [];

function findHeader(src, headTag, index) {

var head = $(src).find(headTag).get(0);

temp_articles[index].headlinethumb = head.textContent;

temp_articles[index].headline = head.textContent;

}

function refresh() {

var q = $q.defer();

...

angular.forEach(urls, function(URL, index) {

temp_articles.push({

inx: index,

img: img_logos[index]

});

$http.get(URL)

.then(function(sc) {

var src = sc.data.substring(sc.data.indexOf(''));

...

q.resolve();

},

function() {

q.reject();

});

});

return q.promise

}

return {

all: function() {

return temp_articles;

},

get: function(programId) {

return temp_articles[programId];

},

refresh: function() {

console.log('DPG programs refresh triggered');

temp_articles = [];

return refresh()

}

}

}]);

{{art.headlinethumb}}

{{art.headline}}

0
0 Comments

问题出现的原因是在app.js中重复加载了控制器。解决方法是将控制器从app.js中移除,并在controller中进行应用。

在app.js中,状态应该是这样的:

.state('state-name', {
    url: '/state-name',
    templateUrl: "templates/walkthrough/state-name.html"
    //注意这里没有控制器
})

0