Вызов функции AngularJS вызывает останов приложения

0

Посмотрите на этот фрагмент кода:

// 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 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(); от кода, он снова работает правильно. Что не так с кодом? и как я могу это сделать правильно?

  • 0
    Пожалуйста, обновите ваш вопрос с помощью функции, а также укажите, где он использовался.
Теги:

2 ответа

1
Лучший ответ

Переключатель switch1 не существует. Вероятно, вы $scope.switch1(); написать $scope.switch1(); вместо.

  • 0
    Большое спасибо. проблема решена, я должен ждать 11 минут, чтобы выбрать как решено :)
  • 0
    Нет проблем, рад помочь
0

Когда вы вызываете switch1() на вашем контроллере, что фактически будет выполнено, это $scope.switch1(), что является правильным способом сделать это, и это то, что вы должны звонить. Как вы говорите, удаление switch1() заставляет ваш код работать снова, поэтому вы уже ответили на это сами.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню