Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it compatible with angular 1.4/material? #100

Closed
talgatbaltasov opened this issue Jun 17, 2015 · 11 comments
Closed

Is it compatible with angular 1.4/material? #100

talgatbaltasov opened this issue Jun 17, 2015 · 11 comments

Comments

@talgatbaltasov
Copy link

Is it compatible with angular 1.4/material? if yes, can you give some examples how to use without $scope? because $scope is not available in components coontroller

@sompylasar
Copy link

@talgatbaltasov Better use angular-locker as a service.

@egilkh
Copy link
Contributor

egilkh commented Jun 17, 2015

I use it with angular-material 0.10 and angular 1.4 with not problem. And I do nothing else than what I have always done.

What do you mean $scope is not available in components controller? Do you have an example that does not work?

@egilkh egilkh closed this as completed Jun 17, 2015
@egilkh egilkh reopened this Jun 17, 2015
@talgatbaltasov
Copy link
Author

@egilkh here http://www.codeproject.com/Articles/891436/Introduction-to-Basics-of-Angular-newRouter
Each component will have its own Controller identified by "CapitalizedComponentName"Controller. There is one special thing to note is that this controller is a bit different from other controllers. It doesn't need $scope for two-way binding. Angular wont be able to instantiate the controller if we pass $scope in it. It defines its observable properties on this.

@egilkh
Copy link
Contributor

egilkh commented Jun 17, 2015

this.somevariable = $localStorage.somevariable; does not work for you ?

@talgatbaltasov
Copy link
Author

angular.module('doctor.home', [])
.controller('HomeController', ["$localStorage", "$http", HomeController]);
// .controller('HomeController', HomeController1);
function HomeController($localStorage, $http) {
this.save = function(email, password){

    $http({
        method: 'POST',
        url: 'http://doctor-auth.lcl/api/auth/auth/login',
        data: "email=" + email + '&password='+password,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    })
    .success(function(data, status, headers, config) {
        $http.get('http://doctor-auth.lcl/api/auth/user/authToken?auth_token='+data['auth_token']).
        success(function(data1, status, headers, config) {
            data1 = angular.fromJson(data1);
            $localStorage.email = data1['email'];
            this.email = $localStorage.email;

        }).
        error(function (data1, status, headers, config) {
            alert(data1);
        });
    }).
    error(function(data, status, headers, config) {
        alert(data);
    });

}

}
this doesn't work for me

@egilkh
Copy link
Contributor

egilkh commented Jun 17, 2015

angular.module('doctor.home', [])
.controller('HomeController', ["$localStorage", "$http", HomeController]);
// .controller('HomeController', HomeController1);
function HomeController($localStorage, $http) {
    this.email = $localStorage.email;

this.save = function(email, password){

    $http({
        method: 'POST',
        url: 'http://doctor-auth.lcl/api/auth/auth/login',
        data: "email=" + email + '&password='+password,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    })
    .success(function(data, status, headers, config) {
        $http.get('http://doctor-auth.lcl/api/auth/user/authToken?auth_token='+data['auth_token']).
        success(function(data1, status, headers, config) {
            data1 = angular.fromJson(data1);
            this.email = data1['email'];;
        }).
        error(function (data1, status, headers, config) {
            alert(data1);
        });
    }).
    error(function(data, status, headers, config) {
        alert(data);
    });

}
}

Could you try this?

@talgatbaltasov
Copy link
Author

app.js


'use strict';

angular.module('doctor',
['ngMaterial', 'ngStorage','doctor.home', 'doctor.welcome', 'ngNewRouter'])
.controller('AppController', [ '$router', AppController]);
function AppController($router) {
$router.config([
{ path: '/', redirectTo: '/home' },
{ path: '/home', component: 'home' },
{ path: '/welcome', component: 'welcome' }
]);
}
home.html


Hello {{home.name}}!

{{home.email}}

{{home.name}}

i have error
................
Failed to instantiate module doctor due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.0/$injector/modulerr?p0=n...)
at Error (native)
at http://doctor.lcl/bower_components/angular/angular.min.js:6:416
at http://doctor.lcl/bower_components/angular/angular.min.js:37:476
at n (http://doctor.lcl/bower_components/angular/angular.min.js:7:322)
at g (http://doctor.lcl/bower_components/angular/angular.min.js:37:50)
at http://doctor.lcl/bower_components/angular/angular.min.js:37:219
at n (http://doctor.lcl/bower_components/angular/angular.min.js:7:322)
at g (http://doctor.lcl/bower_components/angular/angular.min.js:37:50)
at bb (http://doctor.lcl/bower_components/angular/angular.min.js:40:332)
at d (http://doctor.lcl/bower_components/angular/angular.min.js:19:264

@egilkh
Copy link
Contributor

egilkh commented Jun 17, 2015

I'd recommend you use angular.js instead of angular.min.js while developing to get more meaningful error messages from angular. p0=n... is not that insightful.

Maybe you can reformat your comment after you use that non-minified one? I suspect you'll see the error more clearly (at least I will).

If you could surround the files with triple backticks for the sources that would be nice too.

@talgatbaltasov
Copy link
Author

@egilkh look, this works
angular.module('doctor.home', [])
.controller('HomeController', ["$localStorage", "$http", HomeController]);
// .controller('HomeController', HomeController1);
function HomeController($localStorage, $http) {
this.email = $localStorage.email;
this.save = function(email, password){

    $http({
        method: 'POST',
        url: 'http://doctor-auth.lcl/api/auth/auth/login',
        data: "email=" + email + '&password='+password,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    })
    .success(function(data, status, headers, config) {
        $http.get('http://doctor-auth.lcl/api/auth/user/authToken?auth_token='+data['auth_token']).
        success(function(data1, status, headers, config) {
            data1 = angular.fromJson(data1);
            this.email = data1['email'];
            $localStorage.email = data1['email'];
            // this.$storage.name = data1['name'];
            // this.email = this.$storage.email;
            // this.name = this.$storage.name;
            // alert(this.email);
            // alert(data1);
        }).
        error(function (data1, status, headers, config) {
            alert(data1);
        });
    }).
    error(function(data, status, headers, config) {
        alert(data);
    });

}

}

but in another .html i can't get localstorage

Welcome {{welcome.name}}!

{{$localstorage.email}}

@egilkh
Copy link
Contributor

egilkh commented Jun 18, 2015

Use {{ email }} in the html. And this.email = $localStorage.email; in the
Controller ?

On Thursday, June 18, 2015, talgatbaltasov notifications@github.com wrote:

@egilkh https://github.com/egilkh look, this works
angular.module('doctor.home', [])
.controller('HomeController', ["$localStorage", "$http", HomeController]);
// .controller('HomeController', HomeController1);
function HomeController($localStorage, $http) {
this.email = $localStorage.email;
this.save = function(email, password){

$http({
    method: 'POST',
    url: 'http://doctor-auth.lcl/api/auth/auth/login',
    data: "email=" + email + '&password='+password,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data, status, headers, config) {
    $http.get('http://doctor-auth.lcl/api/auth/user/authToken?auth_token='+data['auth_token']).
    success(function(data1, status, headers, config) {
        data1 = angular.fromJson(data1);
        this.email = data1['email'];
        $localStorage.email = data1['email'];
        // this.$storage.name = data1['name'];
        // this.email = this.$storage.email;
        // this.name = this.$storage.name;
        // alert(this.email);
        // alert(data1);
    }).
    error(function (data1, status, headers, config) {
        alert(data1);
    });
}).
error(function(data, status, headers, config) {
    alert(data);
});

}

}

but in another .html i can't get localstorage
Welcome {{welcome.name}}!

{{$localstorage.email}}


Reply to this email directly or view it on GitHub
#100 (comment).

@egilkh
Copy link
Contributor

egilkh commented Jul 2, 2015

Closing. There is no reason why ngStorage should not be compatible with 1.4 or Material (as design or the angular-material module). Tests does not indicate anything wrong with ngStorage in regards to these 2.

@egilkh egilkh closed this as completed Jul 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants