I'm new in AngularJS
and I have a problem I can't fix.
I am in the index.html
page of my application and I let the user click on an icon which send him into another page in this way:
<div class="col-sm-2">
<a href="text.html">
<img src="../icon-modify.png" id="img-mod-1">
</a>
</div>
In the second page the user can insert a Title and a Subtitle through the <textarea>
tag; after that he can click on a confirm button and come back to the previous page where he can read the title and subtitle just inserted in another custom template thanks to the data binding.
<textarea class="text-area-title-article allWidth
ng-valid ng-touched" ng-controller="EditorController"
rows="1" placeholder="Titolo articolo"
ng-model="input.titlearticle2" >
</textarea>
<div class="col-sm-12 line-3"></div>
<textarea class="text-area-subtitle allWidth ng-valid
ng-touched" rows="1" placeholder="SOTTOTITOLO"
ng-model="input.subtitlearticle2">
</textarea>
<div class="row">
<div class="col-sm-12">
<a href="index.html">
<button type="button" class="btn btn-success" ng-click="setData(input)">
Success
</button>
</a>
</div>
</div>
Here the custom element in the first page in which I want to inject the data from the second page:
<article-2col titlearticle2="{{input.titlearticle2}}" subtitlearticle2="{{input.subtitlearticle2}}"</article-2col>
Here I have my two controllers (the first one is the first page controller, as the second for the second page):
NewspaperController.js
testApp.controller('NewspaperController',
function NewspaperController($scope, Article, $log) {
$scope.input = Article.getArticleObject();
console.log($scope.input);
}
EditorController.js
testApp.controller('EditorController',
function EditorController($scope, Article, $log) {
$scope.input = Article.getArticleObject();
$scope.setData = function(ArticleObject){
if (ArticleObject === undefined ) {
console.log ("its undefined");
} else {
console.log (ArticleObject);
Article.setArticleObject(ArticleObject);
}
Here my service Article.js
, for the data storage:
testApp.factory ('Article', function(){
article = {};
article.titlearticle2 = 'This is a title';
article.subtitlearticle2 = 'This is a subtitle';
return {
setArticleObject: function (articleObject) {
article = articleObject;
},
getArticleObject: function () {
return article;
}
}
The problem is that the method setData(input)
seems to not work, maybe because I'm passing a wrong object
?
Moreover, the method getArticleObject()
works fine because I initialize the title and the subtitle using the service and it works.
Hope you can help me. Thanks in advance!