dop2144 2015-06-30 04:13
浏览 816

在Angular JS中创建一个页面

I am learning Angular JS

Here is my app.js

.when('/forget', {
                title: 'forget',
                templateUrl: 'resources/views/forget.php',
                controller: 'genCtrl'

            })
.otherwise({
                redirectTo: '/login'
            });

I want to display the forget.php file inside resources/views folder

Here is my genCtrl

app.controller('genCtrl', function ($scope, $rootScope, $routeParams, $location, $http, Data) {
    //initially set those objects to null to avoid undefined error
    $scope.forget = function () 
    {
        return 1;
    }
});

When ever i do http://localhost/myapp/#/forget the browser is displaying the content of forget.php and then suddenly taking me to /login.

How can i remain in the same page ?

Update :

Here is my app.js

Here is my genCtrl.js

Here is the console

enter image description here

  • 写回答

1条回答 默认 最新

  • dqyknf4423 2015-06-30 06:11
    关注

    Inspite of writing return '1', please write alert('test') and check the prompt message 'test' and this will not throw you in login page.

    AngularJS will invoke the controller with a $scope object. $scope is the application object (the owner of application variables and functions), to know more about these services please check this link OR example.

    PS: If this stuff helps you please leave me a comment and support :)

    Thanks!

    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部