Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Frederik Prijck
@frederikprijck
Johnathon Sullinger
@scionwest
oh, whoops i see the topic now - thanks
Rhitik Bhatt
@lambainsaan
Hello!
Frederik Prijck
@frederikprijck
hey @lambainsaan
dadepo
@dadepo

I just found that if I use $scope to bind value to view and I use ng-model in an input, the value set in the controller shows in the view by default...but this is not the case if I use the Controller as Syntax.

For example this works:

// Js
var myApp = angular.module("myApp", []);
myApp.controller('MainController', function($scope) {
    $scope.model = "Initial value"
})
// View
<input type="text" name="model" ng-model="model"><br/>

the input onload has the text "initial value"

Frederik Prijck
@frederikprijck
You have to bind to the controller
var myApp = angular.module("myApp", []);
myApp.controller('MainController', function() {
    this.model = "Initial value"
})
dadepo
@dadepo
Never mind...on trying again, everything works as it should...must have overlooked something initially
Frederik Prijck
@frederikprijck
You dont have to bind to scope when using controller as
and use it:
<div ng-controller="MainController as main">
{{main.model}}
</div>
That's how you need to use controller as syntax @dadepo
Not using scope.
Wim Huiskes
@wimhuiskes
good evening all
is angular worth my time to learn?
Frederik Prijck
@frederikprijck
Hey @wimhuiskes .
Depends on what you're plans are with it, but I'd say it's worth it.
Looking for Angular 1 or 2 tho ? :) They're both awesome, but well ... ng2 is new.
Wim Huiskes
@wimhuiskes
i bought a book today, its about 1
Frederik Prijck
@frederikprijck
Depending on your JavaScript knowledge, I'd even start learning 2.
Wim Huiskes
@wimhuiskes
i want to build an app, that stores data, and sents that data by mail to the owner of the app
Frederik Prijck
@frederikprijck
But if you're new to JavaScript aswell, you might wanna start off learning 1.
Wim Huiskes
@wimhuiskes
i am not new to javascripy
t
Frederik Prijck
@frederikprijck
It's not about being new, it's about whether or not you're familiar with modern JavaScript using ES6, Module bundlers etc.
Wim Huiskes
@wimhuiskes
but i think that what i want to build is more backend
i am not familiar with FS6
Frederik Prijck
@frederikprijck
So start with Angular1. :D
Wim Huiskes
@wimhuiskes
but is it possible to build the app i want?
should be easy………..i think (:
Frederik Prijck
@frederikprijck
Angular isn't going to help you store the data and mail the owner.
Wim Huiskes
@wimhuiskes
that would be php
Frederik Prijck
@frederikprijck
Angular is only html/css and JS.
Wim Huiskes
@wimhuiskes
is there any online resource where i can start?
Frederik Prijck
@frederikprijck
Wim Huiskes
@wimhuiskes
@frederikprijck thanks :smile:
Frederik Prijck
@frederikprijck
Goodluck @wimhuiskes !
Wim Huiskes
@wimhuiskes
thanks and nice to meet :smile:
i am from holland, so we are neighbours
Frederik Prijck
@frederikprijck
Yep, I know :D
Ayush Bahuguna
@relentless-coder
@frederikprijck hey, I need help. so, i read a little bit on angular js and watched a few videos on pluralsight. I have been able to store the data of my form, but I can't log it to my console.
Frederik Prijck
@frederikprijck
console.log works. So dus $log.debug
Ayush Bahuguna
@relentless-coder
app.controller("FormCtrl", ["$scope", "$location", "$window", "dataService", function($scope, $location, $window, dataService) {

    $scope.newuser = dataService.details;
    $scope.submit = function() {
      dataService.submitInfo();
    }

       if(document.getElementById('showPswd')) {
      document.getElementById('showPswd').addEventListener("click", function() {
          var pwd = document.getElementById("newPassword");
          if (pwd.getAttribute("type") === "password") {
              pwd.setAttribute("type", "text");
          } else {
              pwd.setAttribute("type", "password");
          }
      });
    }
    if(document.getElementById('last')) {
      console.log(dataService.newuser);
          setTimeout(function() {
            $window.open('http://www.ayushdevelops.com/');
          }, 10000);
    }

    $scope.go = function(path) {
      $location.path(path);
    };
}]);

app.service('dataService', function() {
  var userData = this;
  userData.details = {
    "firstname": '',
    "lastname": '',
    "email": '',
    "number": '',
    "password": '',
    "aadhar": '',
    "pan": ''
  }
  userData.submitInfo = function(){
    console.log(userData.details.firstname);
  }
})
Frederik Prijck
@frederikprijck
You dont want code like this in ur controller: if(document.getElementById('showPswd'))
Ayush Bahuguna
@relentless-coder
well, i am seeing undefined in my console. however the dataService.details is storing values, without loosing them when a new view enters.
Frederik Prijck
@frederikprijck
console.log(dataService.newuser); this will log undefined
Ayush Bahuguna
@relentless-coder
where should I put it then?
Frederik Prijck
@frederikprijck
can u change it to: console.log(dataService.details);
That will give you the result.
Ayush Bahuguna
@relentless-coder
I don't have console.log(dataService.newuser) in my code