我正在尝试将一些外部代码包含在我最近开始工作的角度项目中。我想将这个五彩纸屑动画添加到项目中
http://jsfiddle.net/vxP5q/61/?utm_source=website&utm_medium=embed&utm_campaign=vxP5q
I created a route for the page I need to create in app.js
$stateProvider.state('result', {
url: '/result',
templateUrl: 'templates/result_election.html',
controller: 'ElectionCtrl'
})
由于此页面链接到ElectionCtrl,我将小提琴中的代码插入到ElectionCtrl中,但它似乎对我的页面没有任何影响。小提琴代码包含在此内:
angular.module('election',[]).controller('ElectionCtrl', function($http, $scope, $ionicPopup, $localStorage, $location, $stateParams ,$ionicLoading){})
答案 0 :(得分:0)
您链接的代码只是寻找'0'
的标准JavaScript,并在<canvas id="canvas"></canvas>
上插入动画。为了在有角度的部分中使用它,需要做一些事情。
首先,部分模板$(document).ready
需要具有'templates/result_election.html'
元素。
其次,canvas
中的代码需要移动到可以$(document.ready)
$stateChangeSuccess
中调用的函数,因为ui-router
必须出现在canvas
上查找功能的页面。
更高级的形式是创建一个指令,其中包含模板和要在指令的$compile
阶段执行的代码。