javascript - AngularJS 函数调用导致应用程序停止

标签 javascript angularjs

看这段代码:

// Start AngularJS Application
var application = angular.module('engineers', []);
// Set controller
application.controller('engineers_controller', function($scope) {
    // Seting page meta information
    $scope.description = 'Some Description', $scope.keywords = 'key1,key2,key3', $scope.application_name = 'Sarabon', $scope.googleplus_url = '#', $scope.page_title = 'مهندسین مشاور سرابن',
    $scope.txt1="Well, the way they make shows is, they make one show. That show's called a pilot. Then they show that show to the people who make shows, and on the strength of that one show they decide if they're going to make more shows. Some pilots get picked and become television programs. Some don't, become nothing. She starred in one of the ones that became nothing.",
    $scope.txt2="You think water moves fast? You should see ice. It moves like it has a mind. Like it knows it killed the world once and got a taste for murder. After the avalanche, it took us a week to climb out. Now, I don't know exactly when we turned on each other, but I know that seven of us survived the slide... and only five made it out. Now we took an oath, that I'm breaking now. We said we'd say it was the snow that killed the other two, but it wasn't. Nature is lethal but it doesn't hold a candle to man.",
    $scope.switch1=function(){
        $scope.activetext=$scope.txt1,
        $scope.firstswitcher='fa fa-square';
        $scope.secondswitcher='fa fa-square-o';
    },
    $scope.switch2=function(){
        $scope.activetext=$scope.txt2,
        $scope.secondswitcher='fa fa-square';
        $scope.firstswitcher='fa fa-square-o';
    };
    switch1();
});

我尝试调用switch1()函数onpageloads。但是当我运行我的页面时,几乎所有页面都被破坏并且无法正常工作。当我从代码中删除 switch1(); 时,它再次正常工作。代码有什么问题吗?我怎样才能正确地做到这一点?

最佳答案

函数switch1不存在。您可能想改为编写 $scope.switch1();

关于javascript - AngularJS 函数调用导致应用程序停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38588025/

相关文章:

javascript - 我可以将引用尚未构建的字段的 JavaScript 放在哪里?

javascript - 单击href并将数据存储到输入框中

angularjs - 当所需数据丢失时,如何更改 ui-select 上的边框颜色

javascript - Angular 属性 'parentNode' 在类型 'EventTarget' 上不存在

javascript - 延迟 AngularJS 中的整个页面加载,直到服务的 ajax 完成

angularjs - 带向下钻取的饼图不起作用

javascript - 如何在 Angular js 中从 html 调用函数 Controller ?

javascript - for循环中调用FB api

javascript - 最好使用 "this"还是 "that"(其中 var that = this)?

c# - gridview 行中的 jQuery 确认对话框始终回发