angularjs - Argument passed to $modal is undefined? -
using angularjs ui i'm trying pass argument modal.
the thing is, item undefined. i've checked out documentation etc. , don't i'm doing wrong here.
the controller 'newproject' 1 calling following code:
var modalinstance = $modal.open({ templateurl: 'app/projects/createtask.html', controller: 'createtask vm', resolve: { item: function () { return 'itemvalue'; } } });
inside 'createtask' controller have following code (the beginning displayed here):
(function () { 'use strict'; var controllerid = 'createtask'; angular.module('app').controller(controllerid, ['common', '$modalinstance', createtask]); function createtask(common, $modalinstance, item) { //why item undefined here?!?!?!
note 'newproject' controller located inside 'newproject.js' while 'createtask' controller createtask.js.
for sake of completeness, here complete controllers:
newproject.js:
(function () { 'use strict'; var controllerid = 'newproject'; angular.module('app').controller(controllerid, ['$location', '$modal', '$routeparams', '$window', 'common', 'config', 'datacontext', 'utility', projectdetails]); function projectdetails($location, $modal, $routeparams, $window, common, config, datacontext, utility) { var vm = this; function edittask(task) { var modalinstance = $modal.open({ templateurl: 'app/projects/createtask.html', controller: 'createtask vm', resolve: { item: function () { return 'itemvalue'; } } }); modalinstance.result.then(function (newtask) { task = newtask; vm.projectcost += newtask.cost; }); } } })();
createtask.js:
(function () { 'use strict'; var controllerid = 'createtask'; angular.module('app').controller(controllerid, ['common', '$modalinstance', 'item', createtask]); function createtask(common, $modalinstance, item) { if (item) { alert(item); } else alert('undefined'); } })();
try adding 'item' array in controller definition:
angular.module('app').controller(controllerid, ['common', '$modalinstance', 'item', createtask]);
Comments
Post a Comment